Description of problem:
SearchBuilder v1.7.0 interferes with server-side ajax requests.
Previously using v 1.3.4 I could convert the datatables data object to be sent to JSON format using a function like:
"ajax" : {
"url": 'https://mytargeturl',
"contentType" : "application/json",
"type" : 'POST',
"data": function(d) {
var sb = $('#myTable').DataTable().searchBuilder;
var sbDetails = null;
try {
sbDetails = sb.getDetails();
} catch(e) {
console.log('SearchBuilder not yet initialised!');
sbDetails = {"criteria":[{"condition":"<=","data":"ID","origData":"ID","type":"num","value":["5000"]}],"logic":"AND"}};
}
if (Object.keys(sbDetails).length > 0) {
d.searchBuilder = sbDetails;
}
return JSON.stringify(d);
}
I.e. where normally a FORM is posted I now convert the FORM data to a JSON structure and send an XHR request. This worked well with v1.3.4.
But I recently upgraded to the latest version(s) of datatables and it now uses v1.7.0 of SearchBuilder. The above data function still works but after that searchBuilder.js is still trying to do some stuff on the data which now fails as my function returns a string and not a datatable object.
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Uncaught TypeError: can't assign to property "searchBuilder" on "{\"draw\":2,\"columns\":[{\"data\":\"ID\",\"name\":\"Id\",\"searchable\":false,\"orderable\":false,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ONDERNEMINGSNUMMER\",\"name\":\"Ondernemingsnummer\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"NAAM\",\"name\":\"Naam\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"OPSTARTDATUM\",\"name\":\"Opstartdatum\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ADDRESS\",\"name\":\"Adres\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"REKENINGNUMMER\",\"name\":\"Rekeningnummer\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ACTIEF\",\"name\":\"Actief\",\"searchable\":true,\"orderable\":true,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}},{\"data\":\"ID\",\"name\":\"Action\",\"searchable\":false,\"orderable\":false,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]}}],\"order\":[{\"column\":0,\"dir\":\"asc\",\"name\":\"Id\"}],\"start\":0,\"length\":20,\"search\":{\"value\":\"\",\"regex\":false,\"fixed\":[]},\"searchBuilder\":{\"criteria\":[{\"condition\":\"<=\",\"data\":\"ID\",\"origData\":\"ID\",\"type\":\"num\",\"value\":[\"5000\"]}],\"logic\":\"AND\"}}": not an object
_setUp https://cdn.datatables.net/searchbuilder/1.7.0/js/dataTables.searchBuilder.min.js:4