stateSaveCallback etc on click
stateSaveCallback etc on click
How can I implement stateSaveCallback / "colReorder" / "buttons": ['colvis'] to be enable when the user clicks on a button?
Basically, I need the user to be able to edit the datatable only when he clicks an edit button and the changes to be saved when he press the save button... if the user doesn't press the save button no change will be saved and if he doesn't click on the edit button he won't be able to make any changes... any ideas how to do this? please
This question has an accepted answers - jump to answer
Answers
Not sure I understand your question but does this example do what you want:
https://editor.datatables.net/examples/simple/simple.html
Kevin
Hello @kthorngren
Thanks for your answer but unfortunately is not what I am looking for. What I want is for the user to be able to save the state of the datatable onclick of a button rather than saving it automatically.
if @allan can shed some light I will be grateful
Good question - I don't think that's come up before. There are two options I can think of:
1) Use
stateSaveCallback
to provide your own state save function. When you don't want to save the state, just ignore the function call. When you do, then save it to localStorage or similar. You'd use a flag which is set by the click listener for the logic condition.2) Implement your own state saving, which isn't actually all that difficult. Use
page.info()
,search()
etc to get the information you want, and that save it somewhere. Then you can reload that information into the table whenever required. The advantage of this option is that you could allow the user to save multiple different configurations.Allan
@allan, Thank you a lot allan! Can you provide some examples tho? (or maybe put it into the official documentation? ) I need to save a state into a database by the way so each user can access 'their' state no matter pc they are using. How can ignore the function call?
Hi,
To save Datatables localstorage to DB you may check this tutorial and fork it to your needs. http://refreshmymind.com/datatables-state-save-client-server-side/
You can add a reset button to clear the table preferences, if you want the user to get back to default table settings...
I'm curious, why you want the user to save table preference manually (click of a button)?
I already thought about a case for an admin to save default setting (for each tables) for all users..
@lenamtl I need it so every user can make changes on their own when they really need it and not by accident...
Thanks for the link but I used before and it is not suitable for my needs
xx
Solution:
Yup - that's exactly the sort of thing I had in mind. Nice one!
Allan