Manually call the state restore 'load' action

Manually call the state restore 'load' action

sneaysneay Posts: 2Questions: 1Answers: 0

Hi,

I've had a look around but couldn't find anything regarding this question.

I want to manually call the 'load' action for state restore, this calls an Ajax request in my code to retrieve the list of states saved in the data base.

I catch this in the Ajax function I saw on this example.

 // Action to take if loading states into staterestore
    if (data.action === 'load') {
        $.ajax({
            url: $("#saved_searches_url").data('url'),
            type: 'POST',
            data: {
                type: 'student',
            },
            success: function (response) {
                // Call the callback function with the response
                callback(response);
                console.log('Loaded saved searches successfully.');
            },
            error: function (error) {
                console.error('Failed to load the searches:', error);
            }
        });
    }

My question is if there is a way to manually trigger this callback, I had a look at the API page but also couldn't see anything unless I have missed it: https://datatables.net/reference/api/.

Please let me know if I need to provide any further details but since this isn't really a bug related question I assume I don't need to provide a test case.

Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,445Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Let me just check I've understood correctly - you are basically looking for a way to load the states into StateRestore. Is that correct?

    We have stateRestore.states() as a getter at the moment, but there is no way to use it as a setter, or some other equivalent method. That would need to be added (mildly surprised we missed that in the API actually!).

    Allan

  • sneaysneay Posts: 2Questions: 1Answers: 0

    Hi Allan,

    Yes that is exactly it and thanks for your reply, unfortunate to hear but I will see if I can figure out a workaround.

    Thanks!

  • allanallan Posts: 63,445Questions: 1Answers: 10,465 Site admin

    I just had a look at the page (some impressive strike rates from the batsmen there!) and it looks like you've got a bit of a mix of DataTables stuff - some it redundant. Some of it conflicting. That's why the sorting icons are being repeated.

    I would suggest going to the download page and selecting the parts you need and then using just them, and removing the other stuff. For example you don't appear to be using the pdf export, so remove the pdfmake stuff - that will save nearly 1MB on the page load...!

    Allan

Sign In or Register to comment.