Server-side search with OR condition not working, but works for client-side

Server-side search with OR condition not working, but works for client-side

suelynchsuelynch Posts: 1Questions: 1Answers: 0

I recently switched DataTables from client-side to server-side, however the OR condition does not work for server-side, but it works for client-side. Only a single value search works for server-side. The value in var regex is correct on both, but if an OR condition is entered in the server-side table, no records are returned.

For client-side, I have the table defined as:

var table = $('#example').DataTable( {
"order": [[ 0, "desc" ]], // default to descending application id in first column
"dom": 'l<"top">t<"bottom"ifp><"clear">', // order of everything t-table, i-info,
"language": { // set language for the 'show x entries' menu (now just show x)
"lengthMenu": "Show MENU "
}
});

For server-side, I have the table defined as:

var table = $('#example').DataTable({
"order": [[ 0, "desc" ]], // default to descending application id in first column
"processing": true,
"serverSide": true,
"ajax": {
"url": "/app/api/admin_tables/post_datatable_json",
"type": "POST"
}
});

The code for searching a column has not changed:

$('#status_dropdown').change(function(){
var statuses = $('#status_dropdown option:selected');
var selected = [];
$(statuses).each(function() {
selected.push([$(this).val()]);
});
var regex = selected.join("|");
table.column(2).search(
regex, true, false
).draw();
});

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    That's right, the standard search on the server does that as it's assumed the dataset would be too large to make those wildcard style searches possible. You can modify the script to allow those searches.

    Colin

This discussion has been closed.