Default Column Filters

Default Column Filters

mrkevansmrkevans Posts: 17Questions: 0Answers: 0
edited January 2010 in General
I would like to specify some default filter options.

My data loads from the server, so basically i want it to take the data from the input filters below each column and send that the first time the table loads.

How can i do that?

Replies

  • mrkevansmrkevans Posts: 17Questions: 0Answers: 0
    It seems that i can do something like this:
    oTable.fnFilter("Ebay",2);
    oTable.fnFilter("2",6);

    If i do it right after the declaration of the table, then i get the desired affect. Only problem is that i have done 3 calls to get there, i just wanted my table to load and send the column data on init.

    Also, rather than specifying the index, why not be able to specify the column name for the searching?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    You can use aoSearchCols ( http://datatables.net/usage/options#aoSearchCols ) do do this :-)

    Regards,
    Allan
  • zedd45zedd45 Posts: 3Questions: 0Answers: 0
    Allan, does this work with "bServerSide: true"?

    I've tried passing aoSearchCols a query parameter from the URI, and I was hoping this array would map back to sSearch, which my server scripts is using to filter down my AJAX response.

    I'm also tried chaining fnFilter() after dataTable({ ... }).fnSetFilteringDelay(), but I run into a race condition, causing a JS error.

    [code]
    var initialFilter = [];
    for (i=0, loopCounter = aoCols.length; i
  • zedd45zedd45 Posts: 3Questions: 0Answers: 0
    edited November 2011
    After some additional searching, I found what I was looking for. Seems I overlooked an instantiation parameter:

    "oSearch": {"sSearch" : "MyURLValue"}

    The initial search works great, but when I change the URL parameter, I get the search stored in my cookie from "bSaveState." I see the correct value in "oSearch.sSearch", but the cookie value "wins."

    Is there something else I have to pass to tell DataTables to use the oSearch in preference of the value in the cookie?

    I'm using DataTables Version 1.8.2.

    Here's my new code:

    [code]
    $(dataTableNode).dataTable({
    "aoColumns": aoCols, {% if q %}
    "oSearch": {"sSearch" : "{{q}}"}, {% endif %}
    "bDeferRender": true,
    "bProcessing": true,
    "bServerSide": true,
    "bStateSave": true,
    "fnServerData": fnDataTablesPipeline,
    "sAjaxSource": ajaxDTSource,
    "sDom": 'Clfrtip'
    })
    .fnSetFilteringDelay(500);
    [/code]
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Good to hear you got it working (mostly). If you want DataTables to used the passed in parameter rather than the cookie stored value, just don't set bStateSave:true. It looks like you've got a condition on the search parameter, so I'd suggest adding state save into that.

    An alternative is to use fnStateLoadCallback to remove the filter (again you could put conditional code around that), as is handily shown in the fnStateLoadCallback callback (although not on a per column basis - but that is similar) :-)

    Allan
  • zedd45zedd45 Posts: 3Questions: 0Answers: 0
    Thanks Allan, that looks like just what I need!
    DataTables is insanely flexible & configurable and I'd like to thank you for all your hard work with a donation soon!
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Great to hear its doing the job for you :-)!

    Allan
This discussion has been closed.