Modify columns width before initilization
Modify columns width before initilization
Good morning,
as Datatables doesn't support resizing out of the box, I am currently using the https://github.com/jeffreydwalter/ColReorderWithResize/blob/master/ColReorderWithResize.js which works okay.
One of the issue I am having currently, is trying to preserve the state (width) of the columns. I came with the idea to save the width of tables (using localStorage) or something, but I can't find a way to restore those before table initialization. Is there any way I can modify the column widths before table initilization?
Something like:
$(document).on( 'preInit.dt', function (e, settings) {
var api = new $.fn.dataTable.Api( settings );
....
});
Any ideas will be really appreciated. Thanks.
Answers
https://datatables.net/reference/option/stateSave
If you don't want it for every table you can use this for an individual table:
To allow the user to delete the saved states and go back to the defaults you could use something like this
Hi @dcp ,
As @rf1234 said,
stateSave
is the way to go. By default, column widths aren't saved - only ordering and filtering properties are. However, you can add to what's being saved by usingstateSaveParams
, and then you can reapply those settings on reload insidestateLoadParams
,Cheers,
Colin