Call search manually
Call search manually
marcpirat
Posts: 51Questions: 18Answers: 0
hi
I have a datatable with a custom tool bar who include checkbox
var samplesTestTable = $('#samplesTestsTable').DataTable({
dom: '<"samples-toolbars">frtip',
language: {
"url": urlI18n
},
'bLengthChange': false, //hide 'show entries dropdown
'processing': true,
'serverSide': true,
'pagingType': 'simple_numbers',
'ajax': {
'type': 'get',
'url': url,
'data': function (d) {
var current = $('#samplesTestsTable').DataTable();
d.testTypeValue = "[(${testTypeValue})]";
d.page = (current != undefined) ? current.page.info().page : 0;
d.size = (current != undefined) ? current.page.info().length : 5;
d.sort = d.columns[d.order[0].column].data + ',' + d.order[0].dir;
d.search = d.search.value;
d.testDoneInclude = $("#testDoneInclude").prop("checked");
}
},
'fnDrawCallback': function (oSettings) {
$('.dataTables_filter').each(function () {
$("div.samples-toolbars").html('<div><input type="checkbox" id="testDoneInclude" name="testDoneInclude" class="form-check-input" /><label for="testDoneInclude" class="form-check-label">Test done include</label></div>');
});
},
'columns': [{
'data': 'id'
},
{
'data': 'buildDate'
},
{
'data': 'productTypesName'
},
{
'data': 'productsName'
},
{
'data': 'supplierName'
},
{
'data': 'machineName'
},
{
'data': 'tests',
'render': function (data, type, meta) {
var value = '';
//loop to get rendered
for (i = 0; i < data.length; i++) {
if (value != '') {
value = value + '<br>' + data[i];
} else {
value = data[i];
}
}
return value;
}
}
],
rowCallback: function (row, data) {
if (data.nonCompliant) {
$(row).addClass('nonCompliant');
}
}
});
When checkbox value change, I would like to trigger search
$("#testDoneInclude").on('change', function () {
//call search here
});
This discussion has been closed.
Answers
Here is an example of checkbox searching I created previously.
http://live.datatables.net/vipifute/1/edit
Kevin
In my fnDrawCallback i put
$("#testDoneInclude").on('change', function(){
samplesTestTable.draw();
});
I click the checkbox ( so testDoneInclude is checked), call is done on the server and alfter testDoneInclude is unchecked
any reason?
Looks like the code you have in
drawCallback
is creating these checkboxes?If so then you probably will want to move that code to
initComplete
so that it executes only once at initialization instead of for each table draw.Kevin
same issue, checkbox is uncheck after search
Without seeing the code in action its hard to say what the problem is. For troubleshooting help please post a link to your page are a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin