Individual Column Filtering Using Select

Individual Column Filtering Using Select

lyndonwillyndonwil Posts: 40Questions: 5Answers: 0
edited March 2014 in DataTables 1.10
I've been playing with this example : http://next.datatables.net/examples/api/multi_filter_select.html

At first, I didn't think the code worked... but it does... it's just a little strange

I can't get the example to work at all in Chrome, however, I can get it to work in firefox... And only, if i put an alert in front of the code..

For example

[code]

alert(i);
table.column(i).data().unique().sort().each( function ( d, j ) {
select.append( ''+d+'' )
} );

[/code]

At least, it shows the code works, when a delay is added ?? very odd..

Replies

  • lyndonwillyndonwil Posts: 40Questions: 5Answers: 0
    edited March 2014
    Allan,

    I've got this working.. But just wondered if you can confirm that it's a good solution, before i move on.


    very simply i think it wasn't working because the table hadn't fully loaded from the server. Hence working after placing an alert in the code.

    I've now called the code within the initComplete callback as follows and it works well

    [code]
    "initComplete": function(settings, json) {
    $(".dataTables_scrollFootInner tfoot th").each( function ( i ) {
    var 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( ''+d+'' )
    } );
    } );
    },

    [/code]

    Once again, loving the new changes.. great stuff

    lyndon

    Update : I have just found one issue. The select filters only show data from the current table display. Rather than the full display. So if you display only 10 Rows in the table, the select filters will only populate with those rows... If you have a total of 100 rows. it will ignore the data in the other 90

    My first thought was that the render defaulted to true but i've tried it On and Off. I've also tried using this.Api and i got the same result..
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > I've now called the code within the initComplete callback as follows and it works well

    Bang on. That's exactly how to do it :-)

    > The select filters only show data from the current table display.

    Are you using server-side processing? It only loads the data needed for the current display, so yes, that would happen.

    Allan
This discussion has been closed.