Apply search inputs, but only on some columns

Apply search inputs, but only on some columns

arosiarosi Posts: 4Questions: 2Answers: 0
edited February 2015 in Free community support

Hello Datatablers,

Into this example we can see how to apply search over all columns:

https://datatables.net/examples/api/multi_filter.html

I am now interested if we have a method to apply only on some of them, but avoiding the conditional approach.
As from the above example this is what I wish to avoid:

$('#example tfoot th').each( function () {
if($(this).index() != 3) //we apply search to all of the columns except the one with index 3,
//I don't wish to put conditions in the code, it's just not practic
{
var title = $('#example thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
}
else
{
//add just an empty td instead of the search box, again not practic
}
} );

Also tried the Searchable property, but no results. The search is still there.

I tried it as here but doesn't work with the example above:

http://datatables.net/reference/option/columns.searchable

Thank you,

Andrei

Answers

  • arosiarosi Posts: 4Questions: 2Answers: 0

    So, currently the search display is not dynamic,

    here is a more detailed answer

    http://www.datatables.net/forums/discussion/22167/is-column-searchability-dynamic

  • TerradonTerradon Posts: 16Questions: 5Answers: 2

    I have searching in every possible combination of tables. Just one or combining them.

    This is my footer part:

    <tfoot>
                <tr>
                     <th><div id="dateslider"></div></th>
                    <th>'.$select.'</th>
                    <th><input type="text" placeholder="Zoek op partij" id="partij_search"></th>
                    <th><input type="text" placeholder="Zoek op tegenstander" id="tegenstander_search"></th>
                    <th><input type="text" placeholder="Zoek op beschrijving" id="beschrijving_search"></th> 
                </tr>
            </tfoot>
    

    First column is a jQuery dateslider,
    2nd column is a select input,
    others are text inputs.

    For example;

    $(\'#beschrijving_search\').on( \'keyup\', function () {
            table
                .columns(4)
                .search( this.value )
                .draw();
        } );
    

    is the javascript which catches the search.
    Do this for every column, check in your backend which search items aren't empty and you know what is searching for.
    1 column search will only give one item which is not empty. If more search items are asked for, just add those search items together in a where part for your sql.

This discussion has been closed.