Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82306

Unescape $.fn.dataTable.util.escapeRegex()

$
0
0

Hello,
i need to unescape api's $.fn.dataTable.util.escapeRegex(). I need it to restore state of column filters made with select fields.

I'm doing the select fields with this:

  initComplete: function () {
                    this.api().columns('.select-filter').every(function () {
                        var column = this;
                        var select = $('<select><option value=""></option></select>')
                            .appendTo($(column.footer()).empty())
                            .on('change', function () {
                                var val = $.fn.dataTable.util.escapeRegex(
                                    $(this).val()
                                );
                                column
                                    .search(val ? '^' + val + '$' : '', true, false)
                                    .draw();
                            });
                        column.data().unique().sort().each(function (d, j) {
                            select.append('<option value="' + d + '">' + d + '</option>')
                        });

and restoring state with this:

 var state = table.state.loaded();
            if (state) {
                table.columns().eq(0).each(function (colIdx) {
                    var colSearch = state.columns[colIdx].search;
                   // alert(colSearch.search.slice(1, -1))
                    if (colSearch.search) {
                         $('select', table.column(colIdx).footer()).val(colSearch.search.slice(1, -1));
                    }
                });
                table.draw();
            }

Above code works for me, except situation, when colSearch.search.slice(1, -1) retruns values with special characters. They are with escapes (made by $.fn.dataTable.util.escapeRegex). So i need to do something like unescape this value. Does anyone tried to do that ?

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.


Viewing all articles
Browse latest Browse all 82306

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>