Guidelines for server processed table filtering

Guidelines for server processed table filtering

ttrenevjrttrenevjr Posts: 6Questions: 2Answers: 0
edited January 2015 in DataTables 1.10

Howdy!

I'm new to Data Tables and may i say to programming at all. I've managed to set up my system with DataTables using server processing, however i'm experiencing difficulties setting up the filtering options. While as the global filter is an awesome tool for finding whatever the user wants, i need few checkboxes (and while we're on the subject, some date range filters) to filter some of the results before content is loaded. I've been through the forum and the website and i understand $.fn.dataTableExt. afnFiltering.push() is the way to do that, but i seem to fail at understanding how this mechanism works. Is it possible to give me some basic guidelines in what i need to do?
Here's my table setup

var active = $('#active').DataTable( {

"dom": 'f<"toolbar">rtilp',

    "processing": true,

    "serverSide": true,

    "ajax": "processing_active.php", 

"order": [[ 1, "desc" ]],

"lengthMenu": [[55, 155, 250, -1], [55, 155, 250, 'All']],

    "columns": [

        {

            "class":          "details-control",

            "orderable":      false,

            "data":           null,

            "defaultContent": ""

        },

        { "data": "loadnumber" },

   //.. rest of the data fields

    ],

    "createdRow": function ( row, data, index) {

    // some filters to help me display the status properly

        }

    }

} );

I tried putting basic filter before the table just to try and filter some results to see how this works, but the table is not filtered at all.

$.fn.dataTableExt.afnFiltering.push(

function( settings, aData, iDataIndex ) {

        var aData = status;

        if ( aData == "completed" || aData == "Completed" )

        {

            return false;

        }

        else {return true;}

}

);

This question has an accepted answers - jump to answer

Answers

  • ttrenevjrttrenevjr Posts: 6Questions: 2Answers: 0
    edited January 2015

    Is it possible to have something to do with the datables version?

  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin
    Answer ✓

    $.fn.dataTableExt. afnFiltering.push() is the way to do that

    No - not if you are using server-side processing. The variable you note is client-side and therefore only useful for client-side processing - the server (where filtering must occur if you are using server-side processing!) has no knowledge at all of that array.

    If you want extra filtering in server-side processing you need to update whatever server-side processing script you are using to perform that extra filtering.

    Allan

  • ttrenevjrttrenevjr Posts: 6Questions: 2Answers: 0

    Ok i understand now. There's no way to filter the results without making new request to the server. I found Daniel's yadcf plugin, which is great, but what would you recommend in this case scenario?

  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin

    YADCF works with server-side processing as far as I am aware, but obviously if you want to implement some of the complex filters (such as date ranges) you need to write the code for that in the server-side script.

    Allan

  • ttrenevjrttrenevjr Posts: 6Questions: 2Answers: 0

    Ok. Thanks for all your work fella! Next time i meet you, i'll get you a beer :)

This discussion has been closed.