Migrating to Datatable 2 search stopped working. on search drawCallback not triggered
Migrating to Datatable 2 search stopped working. on search drawCallback not triggered
var table = $(table_name).DataTable({
"scrollX": true,
"scrollY": "400px",
fixedHeader: true,
displayStart: displayStart,
searchHighlight: true,
order: [],
columnDefs: columnDefs,
"sDom": 'lBfrt',
"responsive": true,
buttons: [
{
extend: 'excelHtml5',
className: 'btn btn-secondary red-button1',
text: '<i class="excelicon"></i>',
titleAttr: obj.pageName,
title: ""
}
],
stateSave: false,
serverSide: true,
searching: true,
scrollCollapse: true,
fixedColumns: {
leftColumns: leftColumn
},
pageLength: pageLength,
ajax: {
url: obj.url,
data: obj.data,
type: 'post',
processing: true,
},
ordering: false,
columns: columnvalue,
drawCallback: function () {
$('.dataTables_paginate.paging_simple_numbers').removeClass('hidden');
$('.paginate_button.next').removeClass('disabled');
if (table.data().count() < 100) {
$('.paginate_button.next').addClass('disabled');
}
removeLoader("tableContainer");
setTimeout(function () { addTableExtraEvents() }, 500);
}
});
if (table) {
table.on('xhr.dt', function (e, settings, json, xhr) {
if ("_SesionOut_" === json) { window.location.href = rootDir + "Error/Index?settings=Your session has been expired" }
});
$('#table1_filter label input[type="search"]').unbind();
$('#table1_filter label input[type="search"]').keyup(function (e) {
if (e.keyCode === 13) {
table.on('preXhr.dt',
function (e, settings, data) {
data.start = 0;
});
table.search(this.value).draw();
}
});
}
Answers
Can you link to a test case showing the issue please? Ideally in this case, two test cases - one showing the old behaviour that you want and the new one.
Thanks,
Allan
Using datatable old version 1.10.20 with attached code search was working fine,
then updated datatable to 2.0.8 with same code search stopped working. I found that drawCallback is not calling while searching.
How have you verified that
drawCallback
is called not called when searching?drawCallback
is called when searching in this test case case:https://live.datatables.net/pozatiju/1/edit
This issue has not been reported before and normally works as expected. Allan asked for a test case showing the issue to debug. Please post a link to a test case or update mine to show the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi Kevin below is my code:
Hi Kevin
I have attched code file
plz find and help me
Thanks
Hi Kevin,
I have also updated code in your link https://live.datatables.net/pozatiju/2/edit
When firsttime grid load drawCallback calling and data displayed as expected. but its not working while on search and not getting any error in console.
Your test case is getting this error and is not running:
Your
ajax.url
is referencing the variableobj.url
which is not assigned in the test case. The test case actually needs to run and show the issue for us to help debug. Use the ajax config from my test case.Try placing a
console.log
statement in yourdrawCallback
to confirm if it runs or not.Your code is adding or removing classes. Are you expecting something to change on each draw? I don't think anything will change. As I asked before how have you determined
drawCallback
isn't running for each search?I'm not sure what
addTableExtraEvents()
does but if it adds event handlers thendrawCallback
might not be the place to call this function as it will add a new event handler each draw. Likely you will want to do this only once ininitComplete
.Kevin