• Resolved Power Design

    (@power-design)


    Hello Tobias,
    Great plugin! (definitely 5 stars :))
    I am looking for the best way to go about allowing users to search for a specific value within a range of values in a cell.
    For example, one table I am working on has a column for Grade Range. I would like to have a drop-down list of grades, and when one is selected, entries that have a range that grade falls into would appear. So if the user selects “3rd” from the list, the entries with “1st-12th,” “3rd-4th,” and “K-8th” would all appear.
    I don’t mind manually editing each entry, I just need some advice for the best way to go about this.

    Thank you very much for the support!

    ~Anthony

    https://www.ads-software.com/plugins/tablepress/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi Anthony,

    thanks for your question! Good to hear that you like the plugin!

    The best approach that I see here would be to use the DataTables ColumnFilterWidgets Extension from https://tablepress.org/extensions/datatables-columnfilterwidgets/ and its datatables_columnfilterwidgets_separator Shortcode parameter (see https://datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/separator.html for details), used on a hidden column that has all the values that match.
    So, basically, you would create a second column for the Grade Range, that has all individual entries, corresponding to the actual range in it.
    So, if the range in the first column is “3rd-4th”, the cell in the new column would be “3rd,4th”. If the value is “K-8th”, the value in the new column would be “K,1st,2nd,3rd,4th,5th,6th,7th,8th”, and so on.
    You could then use a Shortcode like

    [table id=123 datatables_columnfilterwidgets=true datatables_columnfilterwidgets_exclude_columns=2 datatables_columnfilterwidgets_separator="," /]

    to invoke the functionality.
    The datatables_columnfilterwidgets_separator parameter would honor the list of comma-separated values, while the datatables_columnfilterwidgets_exclude_columns parameter would make sure that there’s no dropdown for the original column.
    Then, we’d just have to hide the new column by adding this to the “Custom Commands” textfield on the “Edit” screen of the table:

    "aoColumnDefs": [ { "bVisible": false, "aTargets": [ 2 ] } ]

    (The 2 would result in the third column being hidden, as counting the columns starts with 0 in this piece of code.)

    Regards,
    Tobias

    Thread Starter Power Design

    (@power-design)

    That worked great! Thank you very much for your time.
    One last thing:
    Is there a way to have the grades list in order in the dropdown? 10th, 11th and 12th are listed before 1st because they lead with a 1.

    Thank you!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Unfortunately, I’m not aware of a solution for that sorting ?? Sorry. The JS library will sort the list as strings, which is why you are seeing this result. Changing that would require a different sorting, but I’m not sure how to add that to the JS code. Sorry.

    Best wishes,
    Tobias

    Thread Starter Power Design

    (@power-design)

    Ah well. I’ll see if they’ll sort if I use only the numbers instead of adding “th” or “rd” on the end.

    Thank you for your time!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? I hope that you can find a solution that sorting problem!

    Best wishes,
    Tobias

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Looking to Search within a Range of Values’ is closed to new replies.