Specify column filter by name

Specify column filter by name

totosaliktotosalik Posts: 2Questions: 2Answers: 0
edited May 2014 in Free community support

Hello community,
I hope you can help me. I just started out using DataTables with Jquery. I want to change below example code to allow me to specify the column to set a dropdown filter on. So instead of using all columns like in the example I want to use only one column.

http://datatables.net/examples/api/multi_filter_select.html

What do I need to change for this?

$("#example tfoot th").each( function ( i ) {
    var select = $('<select><option value=""></option></select>')
        .appendTo( $(this).empty() )
        .on( 'change', function () {
            table.column( i )
                .search( $(this).val() )
                .draw();
        } );

    table.column( i ).data().unique().sort().each( function ( d, j ) {
        select.append( '<option value="'+d+'">'+d+'</option>' )
    } );
} );

In addition can I also specify the way the table gets sorted? For example the column I want to filter via a dropdown is location which is also the very first column. So at the moment I get an asc order. But can I define which entries I want to show up first? Or should I do that in the mysql statement?

UPDATE: I solved the column part by just putting if(i==0){...
but what about the sorting?

Thank you,
Thorsten

This discussion has been closed.