Distinct Filter?

Distinct Filter?

CharlesCharles Posts: 1Questions: 0Answers: 0
edited September 2010 in General
First I want to say that DataTables is about the handiest plug-in ever. It’s so powerful and made everything else so easy that I now have the opportunity to add this complexity...

I need to filter a single column and display records with distinct values. Here is an example (airline flight key codes)...

The column contains values like this:
US0001SEAPHX290910US0002PHXSEA061010
US0001SEAPHX290910US0888PHXSEA061010
US0001SEAPHX290910US0999PHXSEA061010
...
US0777SEAPHX290910US0002PHXSEA061010
US0777SEAPHX290910US0888PHXSEA061010
US0777SEAPHX290910US0999PHXSEA061010

For the above dataset, the filter would need to show just two records based upon the uniqueness of the first half of the key code:

US0001SEAPHX290910
US0777SEAPHX290910

Is this beyond the reach of a regular expression filter?

Replies

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Hi Charles,

    That's certainly possible - although it will require a little bit of work I suspect (at the same time - not too much!). What I think you will need to do is create a custom plug-in filter ( http://datatables.net/development/filtering ) in order to link the rows together (i.e. they have a relationship, which the built in filtering cannot be used for - each row is treated individually).

    So what I think will be needed with the custom filter is to create an initially empty array which will contain the unique parts of the key. Then when filtering, if the key is not in the array, display it and add to the array. If it is in the array, don't display it and move on.

    Regards,
    Allan
  • TheNCRTheNCR Posts: 1Questions: 0Answers: 0
    Hi Allan,

    I'm having trouble to understand your proposed solution.
    I also have a requirement to filter "distinct" rows in my dataTable. In my case, it's a little bit different, since I have several "Show Unique" checkboxes displayed in the header of different particular columns.

    The expected behavior is similar: When user clicks one of these checkboxes, the table should be filtered by showing only the first row with a distinct value in that specific column.

    I'm guessing this can be done with datatables API, also by using a custom filter, but I'm having trouble to picture how the solution should look like.

    Thanks for all your development and help,
This discussion has been closed.