'Search a value with parenthesis in Datatable search not giving the result

I have the following code which is used to create the datatble and filter the value, but when the value contains parenthesis then the search is not giving any result though value can be seen if I chose to see All.

I have used both the

column.search(val ? '^' + val + '$' : '', true, false).draw();

and

var val = $.fn.dataTable.util.escapeRegex(
                                         $(this).val()
                                     );

But it is not able to search the value with parenthesis.

Below is the full code snippet

initComplete: function () {
                         this.api().columns([1,2,3,4,5,6]).every(function () {
                         var column = this;
                         var select = $('<select style="width:130px; font-size: 13px;text-align-last: center; padding: 2px 1px 2px 1px; background: #fff; border: 1px solid #ccc; border-radius: 6px;position: relative; "><option value="">(All)</option></select>')
                        .appendTo($(column.footer()))
                          .appendTo( $(column.footer()).empty() )
                                 .on('change', function () {
                                     var val = $.fn.dataTable.util.escapeRegex(
                                         $(this).val()
                                     );
                                    alert("Asche::"+val);
                                     column
                                         .search(val ? '^' + val + '$' : '', true, false)
                                         .draw();
                                 });
                             column.data().unique().sort().each(function (d, j) {
                                 select.append('<option style="text-align-last: right;" value="' + d + '">' + d + '</option>')
                    } );
                } );
            }


Solution 1:[1]

replace $(this).val with

$(this).val().replace(/\+/g,'\\+').replace(/\(/g,'\\(').replace(/\)/g,'\\)')

it works for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salman ansari