table.row is not a function
table.row is not a function
athsalkj
Posts: 1Questions: 1Answers: 0
var table = $('#example').DataTable(
{
"sServerMethod": 'POST',
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "user", "value": userId} );
aoData.push( { "name": "_token", "value": '{!! csrf_token() !!}' } );
},
"bProcessing": true,
"sAjaxSource": "/example",
"aoColumnDefs": [
{
"bSortable": false, "aTargets": nonSortTargets,
},
{
"bVisible": false, "aTargets": hideTargets,
}
],
"oLanguage": {
},
language: {
searchPlaceholder: "Search records"
},
"aaSorting": [[ sortTargets, "desc" ]],
"sPaginationType": "bootstrap",
"iDisplayLength": 10,
"bAutoWidth": false,
"aoColumns": [
{ sWidth: '10%' },
{ sWidth: '11%', sClass : "hidden-xs" },
{ sWidth: '11%', sClass : "hidden-xs" },
{ sWidth: '11%' },
{ sWidth: '13%' },
{ sWidth: '13%' },
{ sWidth: '24%' ,sClass: 'dt-control'}
]
});
// Add event listener for opening and closing details
$('#example').on('click', 'td.dt-control', function () {
console.log(table);
var tr = $(this).closest('tr');
var row = table.row(tr)
//var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
} else {
// Open this row
row.child(format(row.data())).show();
tr.addClass('shown');
}
});
This is my javascript code
please help to fix the issue.
Answers
Based on your code snippet it looks like that should work. What does the
console.log(table);
show?Are you assigning the variable
table
elsewhere in the script?Maybe the
var table = $('#example').DataTable(
assignment is not in a context available to the function in line 40. It will take some general Javascript troubleshooting to debug. Maybe this TypeError: "x" is not a function doc will give you some ideas. If you still need help please post a link to your page or a test case replicating the issue so we can help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin