DataTablesSrc icon indicating copy to clipboard operation
DataTablesSrc copied to clipboard

Add dynamic defaults

Open manusfreedom opened this issue 2 years ago • 2 comments

Useful for retrieving default values from Ajax or for defining certain parameters using a function) :

$.fn.dataTable.defaults = function(){
    myDefault = $.extend({}, $.fn.dataTable.defaults, { "serverSide": true });
    myDefault.stateSave = getFromAjax($(this).attr("id"), "stateSave");
    return myDefault;
}

manusfreedom avatar Nov 16 '23 13:11 manusfreedom

Thanks for suggesting this. I'm not sure about it to be honest, but then that might just be because I'm not to sure where this would be useful over just setting the defaults in a common function. Are you able to give an example?

Thanks!

AllanJard avatar Nov 16 '23 15:11 AllanJard

We mainly use Datatables for 50 different tables and store personal parameters in our database using an API, but each table has its own specific parameters (and some can be global and overloaded) such as stateSave. Each table has its own JS, so there's no need to put common managed (but personal) parameters on each JS. We give users the choice of using a default saveState value, but this can be overridden in each table and linked to the user rather than the session/browser.

Edit: We use stateRestore extension too.

manusfreedom avatar Nov 17 '23 10:11 manusfreedom