How to filter rows on selected dropdownlist value?

How to filter rows on selected dropdownlist value?

vfhvfh Posts: 2Questions: 1Answers: 0
edited September 2016 in Free community support

Hey there,

i would like to know if there is any function to filter a datatable that includes columns with dropdownlist elements?

if we have a dropdownlist with values

<select class="form-control selectBoxForCustomData">
<option>Not done</option>
<option>Done</option>
<option>Yes - failed</option>
<option selected="selected">N/A</option>
<option>Checked by DL</option>
<option>-</option>
</select>

and we search all rows that have "Done" selected
-> <option selected="selected">Done</option>

i tried something like
table.column(index).data().search('Done').draw()
but that draws all rows because the option value "Done" is in every row.

How can i do a HTML search on every row?
eg.: search('<option selected="selected">Done</option>').draw()

Another solution could be adding a hidden html data field with the selected value, but i still need to search in the raw HTML data...

<input value="Done" id="item_ProjectCustomData_XY" name="item.ProjectCustomData.XY" type="hidden">

Haven´t found a solution, yet.

fiddle

Answers

  • vfhvfh Posts: 2Questions: 1Answers: 0

    Workaround:

    set the data-search attribute on the <td> - element and add a changehandler for all dropdownlists.

    ...
    <td>Project A</td>            
    <td data-search="Done">
           <select class="form-control selectBoxForCustomData" id="item_ProjectCustomData"         
             name="item.ProjectCustomData"><option>Not done</option>
            <option selected="selected">Done</option>
            <option >Yes - failed</option>
            <option>N/A</option>
            <option>Checked by DL</option>
            <option >-</option>
            </select>
    </td>
    ...
    

    fiddle

This discussion has been closed.