Adding a filter by year option
Adding a filter by year option
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
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.
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