Deep link into DataTables with regex

Deep link into DataTables with regex

trongarttrongart Posts: 222Questions: 51Answers: 0

I am not sure how to provide a test case for this question, but maybe it needs none:

Following this example to Deep link into DataTables, is it possible to use a regex search such as below:

In the search field:

software|Accountant

In the URL ( replacing | with %7C ):
https://datatables.net/blog/2017-07-24?search.search=software%7CAccountant

Using the following in my datatables:
"search": {
"regex": true,
"smart": false
},
Regex works correctly when the link is normal without search.search. As soon as ?search.search is added to the URL, regex no longer works. However, search.search is working correctly for non regex values.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    You would need to include search.regex in the URL and also in your deep link configuration. Perhaps you can give me a link to your page so I can take a look?

    Allan

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    Appreciate your help @allan - if I include search.regex in the URL, would it be something like this:

    https://datatables.net/blog/2017-07-24?search.regex=software%7CAccountant

    This does not produce results in my page (global search box stays empty). Is there maybe something I need to activate for regex to work with this plugin?

    I use the following structure:

    var searchOptions = $.fn.dataTable.ext.deepLink( ['search.search'] );
    var defaultOptions = {.......
    "search": {
    "regex": true,
    "smart": false
    },.....
    };
    var table = $('#example').DataTable($.extend( defaultOptions, searchOptions ));

    This structure works for non-regex search.search.

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    Correction: I do get results when using ?search.regex in the URL as above, but the global search box stays empty.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    You'd need something more like this:

    ?search.search=software|Accountant&search.regex=true&search.smart=false
    

    That doesn't work on my link above because the deepLink extension isn't setup to look for search.regex and search.smart. The initialisation would need to be extended for them.

    Note that the strings given to deepLink map directly to the DataTables options. So search.regex is expected to be a boolean.

    Allan

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    This works! Thank you @allan

Sign In or Register to comment.