admin管理员组文章数量:1387358
I was having a problem regarding Datatables, when i try to edit my data from the datatable it goes all well, after the datatable refreshes my edit / delete buttons does not work and it throws this kind of error Uncaught TypeError: Cannot read property '_aData' of undefined
.
Here is my UI for the datatable. Datatable image here.
Here is my code for the event for the edit.
$('#template_table tbody').on('click','.update',function(){
var closestRow = $(this).closest('tr');
var data = templateTable.row(closestRow).data();
console.log(data);
tableId = data.id;
$('#modal-title').text('Update Template');
$('#alert_lvl').val(data.alert_lvl);
$('#internal_alert').val(data.internal_alert);
$('#scenario').val(data.possible_scenario);
$('#response').val(data.remended_response);
$('#submit_template').text("UPDATE");
$('#template_modal').modal('toggle');
});
And this is my save function that will refresh the datatable to show the updated one.
function reloadTable() {
$('#template_table').DataTable().clear();
$('#template_table').DataTable().destroy();
template_table = $('#template_table').DataTable( {
"processing": true,
"serverSide": false,
"scrollX": true,
"ajax": '../munications/fetchalltemplate',
columns: [
{ "data" : "id" , title:"ID"},
{ "data" : "alert_lvl", title:"ALERT LEVEL"},
{ "data" : "internal_alert", title:"INTERNAL ALERT"},
{ "data" : "possible_scenario", title:"POSSIBLE SCENARIO"},
{ "data" : "remended_response", title:"RECOMMENDED RESPONSE"},
{ "data" : "last_update_by", title:"LATEST MODIFICATION"},
{ "data" : "functions", title: "*"}
]
});
}
then if i hit update again. i throws the error right here in this part.
var data = templateTable.row(closestRow).data();
Thank you in advance if you can help me.
I was having a problem regarding Datatables, when i try to edit my data from the datatable it goes all well, after the datatable refreshes my edit / delete buttons does not work and it throws this kind of error Uncaught TypeError: Cannot read property '_aData' of undefined
.
Here is my UI for the datatable. Datatable image here.
Here is my code for the event for the edit.
$('#template_table tbody').on('click','.update',function(){
var closestRow = $(this).closest('tr');
var data = templateTable.row(closestRow).data();
console.log(data);
tableId = data.id;
$('#modal-title').text('Update Template');
$('#alert_lvl').val(data.alert_lvl);
$('#internal_alert').val(data.internal_alert);
$('#scenario').val(data.possible_scenario);
$('#response').val(data.remended_response);
$('#submit_template').text("UPDATE");
$('#template_modal').modal('toggle');
});
And this is my save function that will refresh the datatable to show the updated one.
function reloadTable() {
$('#template_table').DataTable().clear();
$('#template_table').DataTable().destroy();
template_table = $('#template_table').DataTable( {
"processing": true,
"serverSide": false,
"scrollX": true,
"ajax": '../munications/fetchalltemplate',
columns: [
{ "data" : "id" , title:"ID"},
{ "data" : "alert_lvl", title:"ALERT LEVEL"},
{ "data" : "internal_alert", title:"INTERNAL ALERT"},
{ "data" : "possible_scenario", title:"POSSIBLE SCENARIO"},
{ "data" : "remended_response", title:"RECOMMENDED RESPONSE"},
{ "data" : "last_update_by", title:"LATEST MODIFICATION"},
{ "data" : "functions", title: "*"}
]
});
}
then if i hit update again. i throws the error right here in this part.
var data = templateTable.row(closestRow).data();
Thank you in advance if you can help me.
Share Improve this question asked May 12, 2017 at 7:09 John GeliberteJohn Geliberte 912 silver badges10 bronze badges2 Answers
Reset to default 4I initialize the datatable every time i reload the datatable and it worked properly.
under reloadTable function.
var templateTable = $('#template_table').DataTable();
The problem in your code is in the declaration of closestRow
variable.
According to jQuery docs, the .closest() function searches for the closest element (respecting the given selector) traversing the DOM upwards.
This means that since you're binding this action to the click on the table's body, you're basically searching for a <tr>
element among the parents of that table.
You can do what you want with another selection method
var closestRow = $(this).children('tr:first');
本文标签: javascriptUncaught TypeError Cannot read property 39aData39 of undefinedStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: Cannot read property '_aData' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744544937a2611840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论