data.stateRestore into function of custom button
data.stateRestore into function of custom button
trongart
Posts: 222Questions: 51Answers: 0
As per this example, is it possible to pass the data from stateRestore data.stateRestore
into a function of the custom button?
Answers
You can call the API within the custom button's code -
stateRestore.states()
give you data about all the states,Colin
Thank you for looking into this! I tried this here, but it does not seem to get the needed array.
If this works, how would I also get the identifier for the specific state of the button clicked so I could get something like this:
table.stateRestore.states(identifier)
I think info here is missing for "Returns a DataTables API containing the desired states so that chaining can occur": https://datatables.net/reference/type/DataTablesApi
You can traverse the DOM to find the State Save name. Use the browser's inspect tool to see the DOM structure. Maybe something like this:
http://live.datatables.net/zocayipi/4/edit
Kevin
@Kevin Getting the state names works, thanks so much! Still not sure how to get the correct array
table.stateRestore.states(identifier)
as the test case seems to hang up.It can be slow to open the console output of the APIs at times. Here is a screenshot:
Is this what you are looking for?
If the test case locks up for you then try it on your local system.
Kevin
@Kevin Apologies! It does work, thank you so much. How do you get to the saved state values specifcally?
console.log(table.stateRestore.states( [name] ).stateRestore);
does not work and neitherconsole.log(table.stateRestore.states( [name] )[38)
;The results are returned into an array of one or more StateRestore objects. You can access the first and only result like this
table.stateRestore.states( [name] )[0]
, for example:http://live.datatables.net/zocayipi/7/edit
Kevin