Filter if vield value is in an ID list and after button click

Filter if vield value is in an ID list and after button click

TxWebTxWeb Posts: 9Questions: 0Answers: 0
edited May 2012 in General
Hello.

I have a datatable that utilizes multiple filters together and they work great. However, we'd like to add one more, the most important, which would be an input box. The data entered in this box would trigger an ajax call to retrieve a list of database returned IDs. These IDs will correspond to certain IDs in the rows that would be placed in a hidden field within the DataTable when it is drawn. We need the filter to then only select those rows with IDs that are in the ID list returned from the ajax call. I can return those IDs from the ajax call and place into JSON or into an array, or whatever is required (and fastest).

First, I don't want this filter triggered automatically when the user starts typing because it will utilize some full-text index logic to pull the list of IDs and I don't want to hose the system with multiple queries. I'd rather have this particular filter be tied to a button that the user can click to initiate this expanded filter/search and then have the logic trigger the filter therefter, in afnFiltering, or any other adequate mechanism.

I am assuming that a custom filter in afnFiltering could be utilized to select (return true) if the hidden ID for each row is in the ajax returned ID list. I've been asked not to redraw the table or repost.

Can anyone please provide some direction?

Thanks so much!
TxWeb

Replies

  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    What is the reasoning behind not wanting to redraw the table? We have multiple input fields that get sent as custom variables through 'aoData.push'. Then the database returns the data found and draws it on the table. No problems so far utilizing this method.

    See: http://datatables.net/examples/server_side/custom_vars.html
  • TxWebTxWeb Posts: 9Questions: 0Answers: 0
    edited May 2012
    Thanks for your response. This table has nested data and additional filters that would be difficult to account for with an ajax response and it would stream too much data, unnecessarily. The code would be much more manageable and utilize less resources if I can simply add an additional filter to narrow the rows more as described herein.

    For instance, say my table has the columns: name, dbID (hidden), someDetailCol, state, dateSomeday. These are not my columns but will easily illustrate what we need.

    Assume the user has already filtered by date and state by utilizing some dropdowns for which we've created the appropriate filters. Assume they now see rows corresponding to hidden dbIDs 20-30. Now, they use an input box and type in some text, to filter further, and hit a button to engage this new filter. At that point, an ajax call would go to a page/service and a list of dbIDs 22,25,26,28,29 would be returned. At this point the new filter would then show the rows that correspond to these hidden IDs. This would be much easier than having to redraw the entire table and utilize much less system resources.

    Can it be done?

    Thanks!
    TxWeb
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    edited May 2012
    Although I haven't tested this I believe you can do what you want by running your ajax call and then calling fnFilter on your dbID column using a simple regex.

    I am thinking your fnFilter would like something like:
    [code]
    fnFilter('2|4|7|83|41', 2, true);
    [/code]

    This would be if the ajax call returned dbID 2,4,7,83 & 41 and your dbID column id was 2.

    See:

    http://datatables.net/api#fnFilter
  • TxWebTxWeb Posts: 9Questions: 0Answers: 0
    Good stuff. I'll try that when I can get back to it next week.
    Thanks!!
This discussion has been closed.