data.stateRestore into function of custom button

data.stateRestore into function of custom button

trongarttrongart Posts: 196Questions: 40Answers: 0

As per this example, is it possible to pass the data from stateRestore data.stateRestore into a function of the custom button?

Test case here

Answers

  • colincolin Posts: 14,442Questions: 1Answers: 2,460

    You can call the API within the custom button's code - stateRestore.states() give you data about all the states,

    Colin

  • trongarttrongart Posts: 196Questions: 40Answers: 0
    edited July 31

    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

  • kthorngrenkthorngren Posts: 16,783Questions: 25Answers: 3,972

    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

  • trongarttrongart Posts: 196Questions: 40Answers: 0

    @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.

  • kthorngrenkthorngren Posts: 16,783Questions: 25Answers: 3,972
    edited July 31

    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

  • trongarttrongart Posts: 196Questions: 40Answers: 0

    @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 neither console.log(table.stateRestore.states( [name] )[38);

  • kthorngrenkthorngren Posts: 16,783Questions: 25Answers: 3,972

    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

Sign In or Register to comment.