DataTables / DataTablesSrc

DataTables source repository
https://datatables.net
MIT License
587 stars 422 forks source link

Add dynamic defaults #250

Open manusfreedom opened 7 months ago

manusfreedom commented 7 months ago

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;
}
AllanJard commented 7 months ago

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!

manusfreedom commented 7 months ago

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.