How can I use the < sign in a search?
How can I use the < sign in a search?
marchoeijmans
Posts: 6Questions: 1Answers: 0
We have data (e.g. product titles) that could have a < sign in it. When I use a < search, these records are not found.
I tried:
- setting the search regex flag to false "search": { "regex": false }
- setting a the escape regex per field to false: "searchCols": [{"escapeRegex": false }]
- setting the smart flag to false
Is there a way to configure DataTables to use the < in search?
Thanks,
Marc
This discussion has been closed.
Answers
Maybe this range filtering example will help:
https://datatables.net/examples/plug-ins/range_filtering.html
Kevin
Hi Kevin,
Thanks for you reply!
I don't understand your answer related to my question. I might have put you on the wrong leg. Let me clarify what I want.
I have a table with product titles, e.g.
'Product 1'
'Product 2'
'Product >'
When I type in '<3' in the search field I want 'Product >' to be found/filtered. It works with the '>' sign, so entering '3>' will find the product but not with the '<' sign.
Hope this clarifies the problem.
Thanks again for the reply.
Regards,
Marc
Sorry, misunderstood. I built a quick example that seems to work:
http://live.datatables.net/lewoceja/1/edit
Maybe you can provide an example with your data showing the issue.
Kevin
Your example seems to work. The only difference I see is that we populate our data from an ajax call. Something like this:
$(document).ready(function () {
$('#resultsTable').dataTable({
"sAjaxSource": "/ProductCatalog/GetProductsAjaxHandler/",
"bProcessing": true,
"bStateSave": true, //To persist sorting ang paging for DataTable
I read somewhere that the sAjaxSource is an old tag, could this be the reason why it is not working in our environment or could it be related to the Ajax call?
Thanks,
Marc
You are using legacy versions of the Datatables options. The legacy format is backwards compatible if you are using Datatables 1.10. I don't have experience with
sAjaxSource
but doubt that is the problem if your table is populating. What Datatables version are you using?Are you using server side processing?
If so then you will need to look at your server script to determine why it doesn't work with
<
.If not then we would need to see an example of your data structure being returned in the ajax response. You can use the network inspector to get this. This tech note will show you how:
https://datatables.net/manual/tech-notes/1
Also we would need to see your full Datatables init code.
Kevin
Hi Kevin,
* We don't use serverside processing, we get all product (records) from the server and filer those records on the client.
* Upgraded to version DataTables.1.10.16
* Copied and pasted the JSON to JSONLint, JSONLint reported that is valid JSON (sample added)
* Added a version of a page with hard coded values that seems to work.
* Added a version of a page that gets the content from a JSON file that doesn't filter the records when I use a < or >.
* I don't understand what code you mean by initialization code.
ps I had to rename the json file to get it uploaded
Thanks,
Marc
Your DT initialisation code should look something like this:
but with more options.
This is what I have in file "retrieved.html" attached .
$(document).ready(function() {
$('#example').DataTable( {
ajax: {
url: './sampleresult.txt',
dataSrc: 'data',
columns: [
{ data: 0 },
{ data: 1 },
{ data: 5 },
{ data: 4 },
{ data: 2 },
{ data: 3 }
]
},
} );
} );
Thanks for the info. I put your data into a test case:
http://live.datatables.net/xuzixete/1/edit
As you state searching for some special characters like @, <, > don't work. I haven't found an option to make it work, short of maybe creating a search plugin. Found lots of similar questions on the forum without answers.
Maybe @allan can help us understand why its not working and the best option to fix it.
Kevin
Thanks, Kevin.
What I don't understand is that when you hard code the values in a table, the search does work event when you use <, > or @ characters. Does this mean that a different kind of search is used when you add the values in a table instead of getting the data from a JSON result?