column search not workoing with special charaters

column search not workoing with special charaters

hsoft2020hsoft2020 Posts: 16Questions: 6Answers: 0

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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • hsoft2020hsoft2020 Posts: 16Questions: 6Answers: 0

    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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Thanks for the test case. It's because you're using $.fn.dataTable.util.escapeRegex() - it's escaping the backslash:

    $.fn.dataTable.util.escapeRegex("1988/11")
    '1988\\/11'
    

    If you remove that, it should do the trick,

    Colin

  • hsoft2020hsoft2020 Posts: 16Questions: 6Answers: 0

    Thanks for your reply. it works

Sign In or Register to comment.