Reputation: 11
I am using Datatables serverside script to populate 9 YADCF filters and it works well. What I need to do is use cumulative_filtering, but I can't find any examples of how I might use cumulative filtering with serverside and what the 'cumulative logic' might look like. Obviously I need the filters to be updated/reload when a value is selected from one of them. Part of my current serverside script looks like this:
$data['yadcf_data_6'] = $db ->selectDistinct( "table_name", [ "type as value, type as label" ], null, "type" ) ->fetchAll();
My JS looks like this:
// YADCF filters Modal
$(document).ready(function () {
'use strict';
var oTable;
oTable = $('#table').DataTable();
yadcf.init(oTable,
[{
column_number: 6,
filter_container_id: 'searchtype',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Type'
},
{
column_number: 7,
filter_container_id: 'searchcategory',
filter_type: "select",
filter_reset_button_text: "Clear",
sort_as: "alpha",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Category'
},
{
column_number: 8,
filter_container_id: 'searchmaterial',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Material'
},
{
column_number: 9,
filter_container_id: 'searchgrade',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Grade'
},
{
column_number: 10,
filter_container_id: 'searchshape',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Shape'
},
{
column_number: 11,
filter_container_id: 'searchcut',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Cut'
},
{
column_number: 12,
filter_container_id: 'searchsize',
filter_type: "text",
filter_reset_button_text: "Clear",
select_type: "chosen",
filter_match_mode: 'exact',
select_type_options: {
'width': '50em',
},
filter_default_label: 'Size'
},
{
column_number: 29,
filter_container_id: 'searchpairs',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Pairs'
},
{
column_number: 31,
filter_container_id: 'searchset',
filter_type: "select",
filter_reset_button_text: "Clear",
select_type: "chosen",
select_type_options: {
'width': '50em',
},
filter_default_label: 'Sets'
}
],
{
cumulative_filtering: true
}
);
});
Is there any sample code that anybody can point out (I can't find any, I've found and used the client side code here ) or if not can somebody give me some hints on where to begin?
Upvotes: 1
Views: 505
Reputation: 37061
The logic is as follows
1) Each time you you use a filter a request is sent to server
2) Based on that request you should query your DB
3) Then based on the query result you should get some rows of data
4) Based on those rows you must populate your current filters elements from that query result (unlike the non cumulative_filtering scenario in which you populate filters elements from the entire data set present in DB)
Upvotes: 0