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

jgreenjgreen Posts: 7Questions: 2Answers: 0
edited April 2015 in Free community support

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

  • larsonatorlarsonator Posts: 54Questions: 4Answers: 2

    ok if i understand this right you have a HTML structure like so?

    <tr>
        <td>
            <select class='mySelect'>
                <option value='TDS' selected>TDS</option>
                <option value='AWS'>AWS</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <select class='mySelect'>
                <option value='TDS'>TDS</option>
                <option value='AWS' selected>AWS</option>
            </select>
        </td>
    </tr>
    

    and you want the search feature to only search for options:selected in the table, instead of all the options?

  • jgreenjgreen Posts: 7Questions: 2Answers: 0

    Yes

  • wilsontcwilsontc Posts: 6Questions: 2Answers: 1

    Likewise, in TableTools the Copy, CSV, Excel, and PDF options include all the options in a select, not just the selected option.

  • wilsontcwilsontc Posts: 6Questions: 2Answers: 1

    Looks like fnCellRender will address my issue.

  • larsonatorlarsonator Posts: 54Questions: 4Answers: 2
    Answer ✓

    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.

This discussion has been closed.