How to access the select All check box if dataTables is defined inside function
How to access the select All check box if dataTables is defined inside function
Hi ,
My dataTables is defined inside function. each row contains checkbox and above datatables body select all checkbox is there .
How to access the selectAll checkbox and eachrow checkbox.
This is my datatables.
$(document).ready(function () {
showDataTable();
// some other functionality
});
var Table;
function displayDataTable() {
Table= $('#example').DataTable(
{
"ajax": {
"url": '@Url.Action("Search", "Home")',
"dataSrc": "",
"dataType": "json",
},
"dom": '<"row"<"col-xs-6"f<"selectAll">><"col-xs-6 text-right toolbar">>rt<"row"<i><l><"col-xs-12"p>>',
"pagingType": "simple_numbers",
"language": {
"info": "Showing START-END of TOTAL",
"loadingRecords": "Loading Data, Please Wait...",
"infoEmpty": "TOTAL entries",
},
"columns": [
{ "data": "" },
{ "data": "CashId" },
{ "data": "PaymentType" },
{ "data": "Amount" },
{ "data": "PhoneNumber" },
{ "data": "Name" },
],
"columnDefs": [
{
searchable: false,
"render": function (data, type, full, meta) {
return '<input type="checkbox">';
},
"targets": [0],
className: "dt-body-center call-checkbox"
},
{ orderable: false, targets: 5 }
],
"order": [[1, 'desc']],
});
$("div.selectAll").html('<div class="xs-margin-left20 "><label><input type="checkbox" id="select-all" />Check All</label></div>');
Table.draw();
}
Below is code that i am trying . Please help us.
$('#select-all').click(function (event) {
var cells = Table.cells().nodes();
$(cells).find(':checkbox').prop('checked', $(this).is(':checked'));
});
// Handle click on checkbox to set state of "Select all" control
$('#example tbody').on('change', 'input[type="checkbox"]', function () {
debugger;
if (!this.checked) {
var el = $('#select-all-checkbox').get(0);
if (el && el.checked && ('indeterminate' in el)) {
el.indeterminate = true;
}
}
});