column search not workoing with special charaters
column search not workoing with special charaters
HI. I have datatable using column search seperately. it does not recognize character like dash.
for example I have date column like "1400-2-15" (its jalali date) or serial column with values like "56t-8u".
wen I search "56t-" in serial col , it returns noting or in date col for search terms like "1400-" it also return nothing.
this is my datatable configuration in search:
initComplete: function () {
var x= this.api().columns().eq(0).each( function (index) {
const column = this.column(index);
const title = $(column.header()).text();
if($(column.header()).hasClass('selectSearch')){
//var titlex=$(`${title}`).appendTo( $(column.header()).empty() );
var select = $(`
<select class="form-control" style="margin-top:15px">
<option value="">${title}</option>
</select>
`)
.appendTo( $(column.header()) )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
});
select.on( 'click', function (e) {
e.stopPropagation()
});
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
});
}
if($(column.header()).hasClass('search')){
var input = $(`
<p class="iinvisible">${title}</p> <input class="form-control" type="text" placeholder="${title}" />
`)
.appendTo( $(column.header()).empty() )
.on( 'keyup change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
column
.search( val )
.draw();
});
input.on( 'click', function (e) {
e.stopPropagation()
});
}
});
} ,
This question has an accepted answers - jump to answer
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi. I made a test page.in this url:
test link
if u see it. you can not search in serial column with dash character. it returns nothing.
Or in birthDate colum if you search "1988/11" also it returns nothing because of slash character. general search field works fine but colum search fields has this problem
Thanks for the test case. It's because you're using
$.fn.dataTable.util.escapeRegex()
- it's escaping the backslash:If you remove that, it should do the trick,
Colin
Thanks for your reply. it works