How to add custom filter to ajax payload (server side processing)?
How to add custom filter to ajax payload (server side processing)?
 markzzz            
            
                Posts: 49Questions: 8Answers: 1
markzzz            
            
                Posts: 49Questions: 8Answers: 1            
            Hi,
I add some custom filters to my DataTable using this simple function:
function FilterRowsByColumnIntFilter(filter, columnName) {
    return $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex, originalData) {
            var selectedValue = parseInt(filter.val());
            var dataValue = parseInt(originalData[columnName]) || 0;
            return (isNaN(selectedValue) || dataValue === selectedValue);
        }
    );
}
Once I apply this filter on the interface, I see the ajax call start to the server. But where do I see this filter settings on the payload? (so I can filter on server side properly)?
Thanks for your helps
This discussion has been closed.
            
Replies
Are you using server-side processing (
serverSide)? If so, the client-side filtering onDataTable.ext.searchwill not be used at all. You need to send the filtering information to the server-side using theajax.datafunction (orpreXhr).Allan
@allan I see, thanks.
Can this preXhr event be linked within:
so every call (also the first) will be triggered automatically for all DataTable I'll bind?
I can do this:
but the first call to the server will miss the filter settings...
The way to use
preXhris to define it like the example in the docs:This way its bound before Datatables initializes.
Kevin
Thanks to everybody!