Automatic add quotes to search
Automatic add quotes to search

Hi,
I have a problem with the search field and I'm not sure if my problem is because I don't understand the search function correctly.
What I want to do is to have the search function work as if I had quotes on my search string. For an example here:
https://datatables.net/extensions/searchbuilder/examples/performance/searchBuilder5k.html If I search for 'ine op' I want to find only columns where these words come in that order like if I added quotes like so "ine op".
I hope that makes sense.
I have this:
var " + tbl.ID + @" = $('#" + tbl.ID + @"').dataTable({
" + DataTableInitExtras + @"
" + (Simple ? @"dom: 't'," : @"") + @"
aLengthMenu: [
[10, 25, 50, 100, 200, -1],
[10, 25, 50, 100, 200, '" + Translate(_ALL) + @"']
],
iDisplayLength: " + (Simple ? @"-1" : @"10") + @",
paging: " + (Simple ? @"false" : @"true") + @",
language: {
buttons: {
copy: '" + Translate(_TO_COPY) + @"',
copyTitle: '" + Translate(_COPY_TO_CLIPBOARD) + @"',
copyKeys: '" + Translate(DATATABLE_CLICK_TO_COPY_ESC_FOR_CANCEL) + @".',
copyInfo: {
_: '" + Translate(DATATABLE_COPIED_X_ROWS_TO_CLIPBOARD) + @"',
1: '" + Translate(DATATABLE_COPIED_ONE_ROW_TO_CLIPBOARD) + @"'
}
}
},
stateSave: true,
initComplete: function () {
this.api().columns().every( function () {
var column = this;
if (column.data().unique().count()<40 && $(column.footer()).data('filter') == '1') {
var select = $('<select><option value=""""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^ *' + val + '$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
var a = $('<div>'+d+'</div>').text()
select.append( $('<option>', { a : a }).text(a) );
} );
}
} );
}
});
});
As you can see the column.search says: ".search(val ? '^ *' + val + '$' : '', true, false )" to enable regex but disable smart search.
This is to have the filter on column working.
How can I setup the search field? Maybe that's already what I'm doing in column.search(...), but I'm not sure.
Answers
Yep, you would need to do the same with the search filter as you are with the columns - i.e. regex. You could re-use the standard input search element as in this example from this thread.
Colin