Reputation: 53
I want to persist with the smart search ( search as i type ) that datatables has. The problem is, one of my columns shows values like: person and personnel. So with million records, it is hard for me to dig down to "person" with the column just showing "personnel" when i type "person".
I do not want only exact match. That would make me type the whole name as in : "person-xyz-123" in some cases.
Is there a way for me to specify say "person" in quotes and tell datatables that i just want to do exact search when i type in quotes and still persist with my normal search ?
Coffeescript file:
$(xyz).ready ->
$('#xyz').dataTable
bProcessing: true
bServerSide: true
sDom: "<\"top\"T>rt<\"bottom\"lip><\"clear\">"
oTableTools:
sSwfPath: "../TableTools-2.1.5/media/swf/copy_csv_xls_pdf.swf"
sAjaxSource: $('#xyz').data('source')
.columnFilter aoColumns: [
{ type: "text" },
{ type: "text" },
{ type: "text" },
{ type: "text" },
{ type: "text" },
{ type: "text" },
{ type: "text" },
{ type: "text" },
{
type: "select"
values: [
{"value": 0, "label": "Failed"},
{"value": 1, "label": "Completed"},
{"value": 2, "label": "Processing"}
]
}
]
return
Upvotes: 0
Views: 712
Reputation: 53
I created this helper function to solve my problem:
def filter_helper(data)
return "#{data[:name]} = :search", search: "#{params[data[:dt_name]].gsub!(/^\"|\"?$/, '') }" if "#{params[data[:dt_name]]}".chars.first == "\""
return "#{data[:name]} like :search", search: "%#{params[data[:dt_name]]}%" if "#{params[data[:dt_name]]}".chars.first != "\""
end
Upvotes: 0
Reputation: 151491
(I'm assuming a 1.9 API since this is what you seem to be using in the question.)
It is possible to do what you want but this means modifying the server-side code that answers to requests made to the URL you give as the sAjaxSource
option. It must perform these checks:
If the sSearch
parameter (which is added to the sAjaxSource
URL) contains a term in double quotes like "person"
then remove the double quotes and perform the match exactly.
Otherwise perform a partial match.
The full documentation of what DataTables sends to the server and what it expects is here.
Upvotes: 1