Row ID after Editor Update
Row ID after Editor Update
Not sure if this question should go in the General Forum, or here in the Editor Forum.
I have a dataTable configured using Editor and everything works PERFECTLY. Love this solution. Here's my problem I'm trying to figure out.
When I Create or Update a record using Editor, everything works except for the following scenario:
On certain pages, I have created an addition external link besides Update and Delete. This link takes you to another page that updates a list of values for the record you were just on. To explain it better, I have a table that is a list of defined Metrics. You can update or delete each Metric using links I've placed in a column of the table:
[code] {
'mData': null,
'bSortable': false,
'sClass': 'center nowrap',
'sDefaultContent': ' '
}
[/code]
Notice the last link named "Values". This calls a function I've created:
[code]
// Values
$('.datatable').on('click', 'a.editor_values', function (e) {
e.preventDefault();
var row = $(this).closest('tr'),
data = oTable._(row),
id = data[0].id;
window.location = '/Metrics/Metric-Values/' + id;
});
[/code]
This links to another page, passing the id of the row as a parameter to make sure we load values for that particular record. Each Metric record can have unlimited Values associated with it.
Now here's the problem. When I load the Metrics page, clicking on that Value link works absolutely fine...it passes the proper row id. However, if I create a New record or Update an existing record, somehow that row id is no longer available and I end up with "undefined" as the parameter when I click on Values and redirect.
All of my JSON results contain an id value and a row[DT_RowId] value when doing creates and updates, and if I inspect the DOM AFTER doing an update, I can still see the correct id attached to the row. It's just somehow not accessible in my a.editor_values function anymore.
I know that was pretty complicated to explain, but if you have any possible suggestions on a way to remedy this situation, I'd appreciate them. It's not a huge deal to ask people to refresh the page, but I'd rather not have to.
Thanks so much!
I have a dataTable configured using Editor and everything works PERFECTLY. Love this solution. Here's my problem I'm trying to figure out.
When I Create or Update a record using Editor, everything works except for the following scenario:
On certain pages, I have created an addition external link besides Update and Delete. This link takes you to another page that updates a list of values for the record you were just on. To explain it better, I have a table that is a list of defined Metrics. You can update or delete each Metric using links I've placed in a column of the table:
[code] {
'mData': null,
'bSortable': false,
'sClass': 'center nowrap',
'sDefaultContent': ' '
}
[/code]
Notice the last link named "Values". This calls a function I've created:
[code]
// Values
$('.datatable').on('click', 'a.editor_values', function (e) {
e.preventDefault();
var row = $(this).closest('tr'),
data = oTable._(row),
id = data[0].id;
window.location = '/Metrics/Metric-Values/' + id;
});
[/code]
This links to another page, passing the id of the row as a parameter to make sure we load values for that particular record. Each Metric record can have unlimited Values associated with it.
Now here's the problem. When I load the Metrics page, clicking on that Value link works absolutely fine...it passes the proper row id. However, if I create a New record or Update an existing record, somehow that row id is no longer available and I end up with "undefined" as the parameter when I click on Values and redirect.
All of my JSON results contain an id value and a row[DT_RowId] value when doing creates and updates, and if I inspect the DOM AFTER doing an update, I can still see the correct id attached to the row. It's just somehow not accessible in my a.editor_values function anymore.
I know that was pretty complicated to explain, but if you have any possible suggestions on a way to remedy this situation, I'd appreciate them. It's not a huge deal to ask people to refresh the page, but I'd rather not have to.
Thanks so much!
This discussion has been closed.
Replies
Good to hear that your Editor testing is going well.
Regards,
Allan
[Object]
0: Object
length: 1
__proto__: Array[0]
if I do the same thing WITHOUT editing the row beforehand, I also get:
[Object]
0: Object
length: 1
__proto__: Array[0]
I honestly have absolutely no idea what that means, but I'm not seeing any difference in what it's outputting. Any ideas?
id = $(this).parents('tr').attr('id');
This seems to work okay. Do you see any concerns with doing it this way? Thanks!
Having said that, it should be in the data source object you are working with - what is in the `object` that your console debug dumps? `console.log( data[0] )` .
Allan
[quote]
Active
true
DT_RowId
3
Description
""
Enterprise
true
Faq
false
Frequency
""
Legend
true
Name
"Call Response"
New
true
ReportId
"SCFR0006"
Sample
true
Schedulable
true
SortOrder
3
Static
false
StaticUrl
""
Updated
true
id
3
[/quote]
after I update, the object looks like this
[quote]
Active
true
DT_RowId
3
Description
""
Engine
1
Enterprise
true
Faq
false
Frequency
""
Legend
true
Name
"Call Response"
New
true
ReportId
"SCFR0006"
Sample
true
Schedulable
true
SortOrder
3
Static
false
StaticUrl
""
Updated
true
[/quote]
You can see that it's missing the id value. I wonder if this is because of the way I'm returning the updated and new objects...
[code]
var response = new {
id = report.Id,
row = new {
DT_RowId = report.Id,
ReportId = report.ReportId,
Engine = report.Engine,
Name = report.Name,
Description = report.Description,
Frequency = report.Frequency,
SortOrder = report.SortOrder,
Active = report.Active,
Schedulable = report.Schedulable,
Sample = report.Sample,
Legend = report.Legend,
Faq = report.Faq,
Enterprise = report.Enterprise,
New = report.New,
Updated = report.Updated,
Static = report.Static,
StaticUrl = report.StaticUrl
}
};
return Json(response, JsonRequestBehavior.AllowGet);
[/code]
I'm using .NET. I've been setting the id value outside of the row values. Is that incorrect?
Editor 1.2.3 has a new `idSrc` option so you could use your `id` property rather than `DT_RowId` btw. Just if you want to reduce redundant information.
Allan