Accessing filtered data

Accessing filtered data

iamstevevaniamstevevan Posts: 8Questions: 4Answers: 0

How do I access just the data that has been filtered? I am able to apply a filter using the example code (below) and implemented some extra code to get just my results. Am I doing this wrong?

Thanks!

var table = $('#example').DataTable();

var scratchData = [];

var filteredData = table
    .columns( [4] )
    .data()
    .eq( 0 )
    .filter( function ( value, index ) {
        if(value === filter) {
            scratchData.push(this.rows(index).data())
        }
    } );
}

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin
    Answer ✓
    var filteredData = table
        .columns( [4], { search: 'applied' } )
        .data();
    

    The selector functions accept a selector-modifier option (see columns() as well) which can be used to modify what rows are selected.

    Allan

  • iamstevevaniamstevevan Posts: 8Questions: 4Answers: 0

    Thanks for the speedy reply allan! So, if I have already applied a search (which I have)

    var results = table.search(
       d.iata,
       $(false), //regex flag
       $(true)  //smart flag
    ).draw();
    

    then I can add the code you suggested to get the data instead?

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin
    Answer ✓

    That should do it. If you want it in a plain array append a call to toArray() as well.

    Allan

This discussion has been closed.