How do I manually populate a filter dropdown and search for rows that INCLUDE selected value?

How do I manually populate a filter dropdown and search for rows that INCLUDE selected value?

alulualulu Posts: 4Questions: 1Answers: 0

Hello!

I have created a datatable here: http://live.datatables.net/tafetano/1/edit?html,css,js,output

This table has various filters with a multiselect ability (using the Select2 Plugin). The filter in question is on the "Skills" column. Right now I have entered various combinations of skills for each employee and the filter is populating with each unique row value for that column. This causes the filter dropdown to contain lists as options such as "Javascript, CSS, HTML". I am trying to figure out how I can manually populate the skills filter dropdown so that each skill is an option and there are no lists ("HTML"/ "Javascript"/ "CSS", etc. as standalone options).

My next problem after figuring out how to manually populate the filter dropdown with the single options would be to get the filter to search for rows that INCLUDE that single value within their list. For instance, I want the user to be able to choose "Javascript" from the filter dropdown and it shows the rows in which an employee has Javascript included in their skill list.

I am stuck on how to achieve this functionality for the skills filter. The skills filter is the only row that needs to function this way, I would like to keep the other filters as they are functioning now. Feel free to tinker with my code linked above, I am very new at this and appreciate any help and examples.

Thanks a lot for your time!

Replies

  • kthorngrenkthorngren Posts: 21,555Questions: 26Answers: 4,994
    edited December 2022

    Good question. You will need to do two things for the Skills column. First is to use a different loop to extract the comma separated items to build the select list. Second is change the regex search to use \\b (word boundary). This should get you started:
    http://live.datatables.net/tafetano/2/edit

    Kevin

  • alulualulu Posts: 4Questions: 1Answers: 0

    Kevin,

    This looks exactly like what I was needing to do, and it worked perfectly on my actual code once tested. I appreciate you taking the time to work it through in my test case, this is so helpful!! Thanks a bunch!

  • kthorngrenkthorngren Posts: 21,555Questions: 26Answers: 4,994

    You are welcome. Its helpful when a running test case is provided :smile:

    Kevin

This discussion has been closed.