search a column on a server back end...
search a column on a server back end...
So I added a search text per column on the header....
initComplete: function () {
this.api().columns().every( function () {
var column = this;
if(column.dataSrc()){
//var select = $('<select><option value=""></option></select>')
var select = $(search_fld);
select.appendTo(column.header());
select.on('keydown', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
tbl_customers.ajax.reload(null,false);
} );
}
} );
},
I have the following situations...
1. I'm expecting the data table to pass the search value as a parameter to the back end... based on https://datatables.net/manual/server-side#Sent-parameters... however, this is not happening... it never populates this column search value.
2. When the user clicks the search to start typing, the click event is propagated to the "order column" event"
3. On my current code, the search is triggered per each character pressed. The default search on DataTables does some kind of "searchDelay" that wait for a period before sending the request to the server. How can I accomplish this?
Thanks,
Luis
This question has an accepted answers - jump to answer
Answers
I tried adding
to avoid the click to propagate, but it still does.
Item one is fixed... I had 2 problems... no need for Regex (I copy that from another example, and was not need it at all)... and second I'm inserting a label with an input inside (for css reasons) "this" was sometimes the input, sometimes the lable... well the label have no value!
I'm still dealing with 2 and 3...
You will need to use two header rows. One for the search inputs and the other for sorting. Something like this example:
http://live.datatables.net/dikuduka/1/edit
Note the use of -option orderCellsTop` to move the sorting to the top header.
The searchDelay is not attached to you custom search inputs. Not sure how to attach a delay to your inputs but you could change the event trigger from
keydown
tochange
so you would have to hit enter.Kevin
Thanks Kevin...
I struggle a little because the columns are passed as a parameter, and dt create a new row themselves... however you pointed me in the right direction... I created a dummy th with the search and attached the events later on.
I'll keep the case open in case someone knows how to deal with the timing issue!
Luis
Found a solution for the timing...