Advanced table row filtering

Advanced table row filtering

vismarkvismark Posts: 79Questions: 5Answers: 0
edited February 2020 in Free community support

Following this question, due to the difficulty in creating advanced custom filtering, I decided to follow standard filter() api route.

I successfully created a regex to match strings different from one or more strings (with this regex: ^((?!string1|string2).)*$) but i'm stuck in building the following regex:

  • string alphabetically greater / greater or equal
  • string alphabetically less / less or equal
  • string alphabetically in range of 2 strings (that means greater or equal AND less or equal)

Could someone please provide support in doing so? I'm quite new to regex patterns...

Replies

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    It seems to me that Regex isn't a good solution for what you want. However if you are interested in learning the rege101 site is a good place to learn and build regex expressions.

    I would look at using a Search Plugin for this. We can help with this if you start by building a simple test case that represents your data.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • vismarkvismark Posts: 79Questions: 5Answers: 0
    edited February 2020

    Thanks Kevin, unfortunately I've unsuccessfully tried the plugin way and found the following downsides:
    - possible conflicts with multi table pages, would have preferred if plugin could be bound to each single table
    - need to manually handle table filters state saving / restoring
    - if you need to filter multiple columns together, $.fn.dataTable.ext.search object is impossible to be kept clean (or you will need to push n single functions with unique identifiable name to handle it): in fact while you keep adding filters there's no problem but if you need to clean or alter one filter, I found no way to get any reference out of that object to clean older functions that should be dismissed

    Plugins wrote that way seems ok if filters are statical and bind to specific columns. Unfortunately in my case I need to reuse code dinamically based on table configs that differ from page to page.

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    I haven't used StateSave much so can't help there but you con modularize your code by creating a Feature Plugin in conjunction with the Search Plugin as described in the Alphabet Search blog. There are three parts.

    This thread shows how to loop through the columns in a search plugin to operate on columns with specific a type as set by columns.type.

    All of this combined will allow you to build search functionality that you can assign to tables via dom option and using columns.type.

    Kevin

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    I've been wanting to clean up my projects and make them more generic and reusable. I've used parts of the above but never put them together in one solution. Thanks to you I spent the afternoon messing with this :smile: Although it can still use some work, I think its a pretty good example showing that combining Feature Plugin, Search Plugin, stateSave and columns.type can support multiple tables on a page in a generic fashion.
    http://live.datatables.net/fuyuboku/2/edit

    Saving and loading the search terms using stateSaveParams and stateLoadParams is straightforward. Using stateLoaded would be too except it runs before init where I initialize the Feature plugins for the tables. I had to use a variable which I reference in init to update the buttons.

    HTH,
    Kevin

This discussion has been closed.