Search/filter dropdowns

Search/filter dropdowns

karliekarlie Posts: 83Questions: 17Answers: 0

Would like some feedback/ideas on how I plan to approach search. I have added 6 select drop-downs from the database, and would like to filter on them when clicked. You can see them here at the top of the page: http://stuartday.co.uk/dtgem/stonelist/index.php

Am I approaching this from the wrong angle? Long term I want make the drop-downs dependent, but for now will just search off of one of the drop-down values. What would be the best way of triggering the search? A function based on the id of the select?

I looked at using YADCF with cumulative filtering, but struggled with the server side code to be honest. Any suggestions welcome.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I would suggest having the drop downs filter per column (column().search()) rather than using the global search as they currently are. The problem with the global search is that there can be only one (unless you create plug-ins).

    This example shows how you could do a cascade filter, but since you are using server-side processing you'd need to update the code and also return extra data from the server on each draw that defines the options for each dropdown based on the current state.

    Allan

  • GreekoGreeko Posts: 4Questions: 1Answers: 0

    The example provided will search on start date and salary, but does not display the selected option after. I'm unable to determine which filter has been selected. Is there a solution to display what is selected?

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    @Greeko Good find. I updated the example here:
    http://live.datatables.net/segubole/1/edit

    The last few lines is where the item is reselected after the rebuild. I added console.log statements so you can see what is happening. The search uses regex and the search term escaped using $.fn.dataTable.util.escapeRegex(). It needs to be unescaped when trying to re-select it. I added a replace statement to remove all \ backslashes (escape character) from the string. This won't work correctly if the original data has backslashes and will need to be adjusted for that.

    Kevin

  • GreekoGreeko Posts: 4Questions: 1Answers: 0

    Right on man. Thank You Kevin

This discussion has been closed.