Is there a way to "remember" the search values of column range filters? (similar to aoPreSearchCols)
Is there a way to "remember" the search values of column range filters? (similar to aoPreSearchCols)
daniel_r
Posts: 460Questions: 4Answers: 67
Hi
Im my plugin YADCF I want to be able to support the bStateSave for my column filters, I know I can use the aoPreSearchCols to load the filters values for my simple filters select/autocomplete, but the more advanced filters range_number/range_date/etc... works a bit differently from the simple ones and because of that their values are not being stored in the aoPreSearchCols (for a good reason) but still before I'll start writing my own cookies I wanted be sure that there is no other way to do it with the help of datatables.
So is there a way to store the range filters values (from - to) with datatables, or I must add my own cookies?
Daniel.
Im my plugin YADCF I want to be able to support the bStateSave for my column filters, I know I can use the aoPreSearchCols to load the filters values for my simple filters select/autocomplete, but the more advanced filters range_number/range_date/etc... works a bit differently from the simple ones and because of that their values are not being stored in the aoPreSearchCols (for a good reason) but still before I'll start writing my own cookies I wanted be sure that there is no other way to do it with the help of datatables.
So is there a way to store the range filters values (from - to) with datatables, or I must add my own cookies?
Daniel.
This discussion has been closed.
Replies
https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.state.js#L32
https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.state.js#L105
This allows modification of the parameters being loaded (you might actually need to use `oSettings.oLoadedState` depending upon when your plug-in is initialised - since stateLoaded might have already fired!).
Regards,
Allan
That could be really helpful. and speed up the development of the yadcf plugin.
Thanks ahead,
Daniel.
Live: http://live.datatables.net/irawin/3/edit
[code]
$.fn.dataTableExt.aoFeatures.push( {
"fnInit": function( settings ) {
var clickCount = 0;
var loadClickCount = 0;
var el = $(''+
'Live click count:
'+
'Load click count: '+
''
);
var redraw = function () {
el.find('span').eq(0).html( clickCount );
el.find('span').eq(1).html( loadClickCount );
};
$(settings.nTable).on( 'click', function () {
clickCount++;
redraw();
settings.oApi._fnSaveState( settings ); // internal function since there is no 'public' api to save state
} );
$(settings.nTable).on( 'stateSaveParams.dt', function ( e, settings, data ) {
data.clickCount = clickCount;
} );
// Load - feature plug-ins init occurs after stateLoaded event,
// so read from the staved state
loadClickCount = settings.oLoadedState && settings.oLoadedState.clickCount ?
settings.oLoadedState.clickCount : 0
redraw();
return el[0];
},
"cFeature": "C",
"sFeature": "TableClicks"
} );
$(document).ready(function() {
$('#example').dataTable( {
dom: "Cfrtip",
stateSave: true
} );
} );
[/code]
I think I should perhaps add `state.save()` , `state.data()` and `state.loaded()` methods to the API to make this cleaner... And I'd do that immediately if I weren't trying to keep the core code size down - its already 2K larger than I wanted for 1.10 and I'm running gout of ideas for how to make it smaller!
Allan
I'm not using the sDom, so I'm not sure that I can use your example :/
I'm looking for a way to save some info to the "state" just after user perform an action (use one of my range filters) and to load it just before the table is being drawn so I will be able to read from state and the table will be filtered according to my $.fn.dataTableExt.afnFiltering pushed logic...
As I said I tried to to find some relevant information but without luck, Also yadcf support atm datatables 1.9 only.
Thanks ahead.
Daniel
Allan
Looks good, and it looks like what I was looking for.