Default filter settings, similar to aaSorting.

Default filter settings, similar to aaSorting.

andrew_mandrew_m Posts: 31Questions: 0Answers: 0
edited March 2009 in General
Hi, Allan.

Seems it is impossible to set default filter values per column, juts like we can set default sorting. We found it useful in our use case - show items with status "Active" by default, and i'm sure there are many other similar use cases. It would be great, if we could setup datatables to get already filtered data from server, similar as sorted and paged.

What you think?

Replies

  • zygimantaszygimantas Posts: 33Questions: 0Answers: 0
    If you will programatically add "default" filter on a column, the client will not be able to remove or change the filtration keyword easily without a special input control. If the will not be able to remove it, there is no reason to select rows which are filtered by default.

    If you want to make the filter removable or changeable and prefer to hide some rows "by default", change filter input value and trigger "keyup" event after the table is loaded.
  • andrew_mandrew_m Posts: 31Questions: 0Answers: 0
    >> If you will programatically add "default" filter on a column, the client will not be able to remove or change the filtration keyword easily without a special input control.

    Yes, and this is our user case. We are not using datatables input controls, we have our own filter controls, like dropdown for entities with specified status and checkbox for show/hide draft entities. In the initial state, grid should show only active entities with no drafts, so we already have 2 filters - and we need to pass these filters to datatables _before_ it send request to ajax source. Ofcourse, user restricted with our filter controls - thats our use case.

    What u think?
  • zygimantaszygimantas Posts: 33Questions: 0Answers: 0
    1. Why do you select this redundant information from database? Maybe you can pass the filtration parameters to Ajax source to get the only information you need?

    2. In other case, if you can not reduce rows count on database or service layer, you can excute oTable.fnFilter() function to filter the rows after they are added to the table.
  • andrew_mandrew_m Posts: 31Questions: 0Answers: 0
    1. I'm not sure i understood, what u mean by redundant information? We select exactly what we need to display. Yes, indeed we can attach our custom filter parameter to ajax request, but why not use datatables existing filter parameters?

    2. Also not sure i understood you. We need to filter rows _before_ they added to datatables, we need to filter entire dataset on the server, then let datatables show all received data.

    We can't use datatables filter input controls. So we have our own control - a dropdown. We call function fnFilter(filterValue, colIndex) each time user selects new value, datatables sends request to server with filter value for certain column in the ajax request and gets filtered data - all works as expected, everything is fine. But our problem is that dropdown control has default selected value, and we need to pass it somehow to datatables, before it issues very first ajax request for data retrieving, ideally during configuration.

    Guys, maybe this suggestion is not valid, or can't be implemented, or i missed some key concept of datatables?
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Andrew,

    I see your point with initial variables, and I think it would be correct to expose them at initialisation time (it might indeed be correct to expose all of the settings object - I'll have a look at that). I think having an initial filtering state ("Enabled" is a good example) is a perfectly valid use case.

    One way that this could actually be done at the moment (since you are using server-side processing) is to add a custom variable to the data sent to the server which will do the filtering for you. In this way, DataTables doesn't need to know anything about it.

    Regards,
    Allan
  • andrew_mandrew_m Posts: 31Questions: 0Answers: 0
    Thanks for the response, Allan.

    Can't wait next beta :)
This discussion has been closed.