How to have search treat a cell's value as the selected value in a dropdown
How to have search treat a cell's value as the selected value in a dropdown
I have a table using DataTables where many of the columns' cells are structured as such
<td>
<select>
....
</select>
</td>
If one of these cells has the value "TDS" selected and the value for that cell in the next row is "AWS" and I search for "TDS" I only want the first row to remain. However, the text for "TDS" is in both rows so search finds it in both. Is there a way to have DataTables treat the value of a cell with a select in it as the selected value for that select?
This question has an accepted answers - jump to answer
Answers
ok if i understand this right you have a HTML structure like so?
and you want the search feature to only search for options:selected in the table, instead of all the options?
Yes
Likewise, in TableTools the Copy, CSV, Excel, and PDF options include all the options in a select, not just the selected option.
Looks like fnCellRender will address my issue.
if you are only searching the drop downs, you could use the search API and a regular expression to search selected option. http://datatables.net/reference/api/search()
http://stackoverflow.com/questions/20804725/how-do-i-get-the-selected-option-text-using-regular-expression
if you are searching all cells at the same time, it might be easier to add a drop down on top of the table, with a list of selections which would appear within your table, and use that as a filter.
im guessing you are using serverside processing, just add the selected filter to your data element, send it to the server and let the server take care of it.