Shubhangi Garg Shubhangi Garg - 4 months ago 75
jQuery Question

Jquery Datatable Error : Uncaught TypeError: Cannot read property '0' of undefined

I have created a datatable using jquery which is as below:
This table has 6 columns. First column is checkbox while the last column has textbox.

$('#multiple-account-table').dataTable({
"data": [
{"accountNumber":"131-202553701","name":"Account 1","dueDate":"10/19/2016","statementBalance":"34.60"},
{"accountNumber":"131-202553702","name":"Account 2","dueDate":"10/19/2015","statementBalance":"14.50"},
{"accountNumber":"131-202553703","name":"Account 3","dueDate":"10/19/2015","statementBalance":"15.50"}
],
"dom": 'it',
"pageLength": 8,
"language": {
"info": "_END_ of _TOTAL_ selected",
"emptyTable": "No records are available",
},
"columns": [
{"data": null},
{"data": "accountNumber"},
{"data": "name"},
{"data": "dueDate"},
{"data": "statementBalance"},
{"data": null}

],
"columnDefs": [
{className: "pad-md-left-p-10 pad-top-bottom-p-10 white-active-bg mouse-link", "targets": [0,1,2,3,4,5]},
{
'targets': 0,
'orderable': false,
'render': function(data, type, full, meta) {
return '<input type="checkbox" name="payment-checkbox" class="multi-checkbox"/>';
}
},
{
'targets': 3,
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).text(date);
}
},
{
'targets': 4,
'orderable': false,
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html('$'+sData);
}
},
{
'targets': 5,
'searchable':false,
'orderable':false,
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html('<span class="bold">Payment Amount</span> <span class="dollar-font-xs">$<input type="number" id="payement-textbox-xs'+index_xs+'" class="payment-xs" min="0" max="100000" step="any" maxlength="9" value="" name="payment-textbox" placeholder="--"/></span>');

}
}
],
"aaSorting": [[3, 'desc'], , [4,'asc'] ],

}); //End of datatable function


And I am getting this error : Uncaught TypeError: Cannot read property '0' of undefined. Any suggestion?

Answer

Check this line, is it so in your code?

"aaSorting": [[3, 'desc'], , [4,'asc'] ],
Comments