Dropdown instead of search box.

Dropdown instead of search box.

joeyzerijoeyzeri Posts: 2Questions: 1Answers: 1
edited December 2014 in General

I am using the Zero Configuration example under Basic initialization. I would like to replace the search text box with a hardcoded dropdown ie:

<select>
<option>Red</option>
<option>White</option>
<option>Blue</option>
</select>

Is this possible?

This question has an accepted answers - jump to answer

Answers

  • joeyzerijoeyzeri Posts: 2Questions: 1Answers: 1
    Answer ✓

    Answered my own question. Make sure the select has an ID :
    <select id="colors"> <option>Red</option> <option>White</option> <option>Blue</option> </select>

    javascript portion:

    $(document).ready(function() {
    var oTable = $('#example').DataTable( {
    "scrollY": "500px",
    "scrollCollapse": true,
    "paging": false

        } );
    
      $('#example').change( function() {
            oTable.draw();
        } );
    

    } );

    $.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
    var selectedColor = $('#colors').val();
    var color = data[0]; // use data for the color column

        if ( selectedColor == color)
        {
            return true;
        }
        return false;
    }
    

    );

This discussion has been closed.