Adding a filter by year option

Adding a filter by year option

OudalallyOudalally Posts: 19Questions: 5Answers: 0

Hello.

I'm using the Datatables plugin with the editor on a client project, and they have asked if there is a quick way to add a filter by year option.
I'm using the search builder currently which can filter by date (arriving and leaving as this is for an accommodation website), but they would like a quick option to show a given year, ideally with a drop down list.

Is there functionality in place already which can be used for this?

Many thanks
Alex

Answers

  • OudalallyOudalally Posts: 19Questions: 5Answers: 0

    I've been looking through the various options which can be supplied when initialising the searchbuilder in the js, however I'm not sure how best to achieve this.

    Ideally, there would be a drop down combo box populated with all the current year and any previous years that appear in the booking data.

  • kthorngrenkthorngren Posts: 22,186Questions: 26Answers: 5,106
    edited July 22

    One option is to use a hidden column (doesn't need to be hidden) that contains just the year. Use columns.render in that column to. get the year from the date column. SearchBuilder should then show that column as an option with just the years displayed. For example:
    https://live.datatables.net/socirone/75/edit

    Or if you want the select element to be outside of SearchBuilder you can create a select element similar to this example. The code that creates the select options will need changed to just get the unique and sorted years.

    Kevin

Sign In or Register to comment.