How do I limit search paramter only to one column in datatables only when using URL paramter

How do I limit search paramter only to one column in datatables only when using URL paramter

Noodles12Noodles12 Posts: 110Questions: 40Answers: 2

I am working on a datatable where I need to limit the search to one column only when using paramater.
example:abc.com?search=test. But, if not passing parameter, it should search all columns. How do I achieve this?

Here is the code I have. Here is the fiddle: http://live.datatables.net/piquxewa/1/edit

Replies

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

    I'm not clear what you would be searching on if there's a parameter - does the search string get passed in a different way?

    That said, if you move the logic into initCompete, you can search however you like - something like this:

        initComplete: function() {
          let api = this.api();
          
          if (false) {
            // full table search
            api.search('an').draw();
          }
          else {
            // specific column search
            api.column(2).search('an').draw();
          }
        }
    

    See example here,

    Colin

  • Noodles12Noodles12 Posts: 110Questions: 40Answers: 2

    Thankyou. This is very helpful. I need this as I want the datatable to search the entire table when user is on that specific page. However, when the user comes from a different page (link with paramter), he should be able to get the results prefiltered for the text entered only for the specific column. Hope it makes sense.

Sign In or Register to comment.