Created
March 2, 2018 13:37
-
-
Save ozknozsrt/b08be2de8b42844840060d6534b97679 to your computer and use it in GitHub Desktop.
dataTable child rows detail info without ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr data-child-name="test1" data-child-value="10"> | |
<td>ParentRow</td> | |
<td>No. 1</td> | |
</tr> | |
In the click handler (line 50 from the example): | |
<script> | |
// Add event listener for opening and closing details | |
$('#example tbody').on('click', 'td.details-control', function () { | |
var tr = $(this).closest('tr'); | |
var row = table.row( tr ); | |
if (row.child.isShown()) { | |
// This row is already open - close it | |
row.child( format( tr.data('child-name'), tr.data('child-value') ) ).hide(); | |
tr.removeClass('shown'); | |
} | |
else { | |
// Open this row | |
row.child( format( tr.data('child-name'), tr.data('child-value') ) ).show(); | |
tr.addClass('shown'); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment