≡

Question/Feature requests for stateRestore default state

Question/Feature requests for stateRestore default state

WernfriedWernfried Posts: 35Questions: 10Answers: 0

Is it possible in stateRestore to set the default/inital state by option or API? I did not find a simple way to do it.

A possible implementation might be an extension of https://datatables.net/ref/core/option/stateRestore.defaults property:

  • true - The end user can set a state to be the default state
  • false - The end user cannot set a default state.
  • "string" - The name of the state to be loaded (if existing) by default

Then the default state could be retrieved for example from URL parameters:

const urlParams = new URLSearchParams(window.location.search);
new DataTable('#myTable', {
    layout: {
        topStart: {
            buttons: ['stateCreate', 'statesList']
        }
    },
    stateRestore: {
        defaults: urlParams.get('state')
    }
});

If such feature becomes available, I think I could convince my manager to go for DataTables Plus

Wernfried

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 66,088Questions: 1Answers: 11,012 Site admin

    If such feature becomes available, I think I could convince my manager to go for DataTables Plus

    You have my attention ;)

    In all seriousness, what you are looking for is already available (assuming I've understood correctly). To have initial states in StateRestore you use stateRestore.predefined and you can set isDefault on the one you want to be loaded up by default.

    Here is a little example.

    Does that match what you want?

    Allan

  • WernfriedWernfried Posts: 35Questions: 10Answers: 0

    Not really. In my application the user will create the states by himself, I don't know the individual preferences and needs of my users. Yes, the user can select which state should be the default - but just one. The user may have 2 or 3 states which they use frequently and they want to open them with one click, typically with a bookmark in their browser or even as part of their start-pages.

    Wernfried

  • allanallan Posts: 66,088Questions: 1Answers: 11,012 Site admin

    Ah I see - many thanks for the clarification. How about if there were an option for when you change state it sets either a search location or a query parameter on the URL. That way you could book mark that URL and StateRestore would check the search or query (depending on the configuration) for that parameter and use the appropriate state. It could be something like ?dtsr=1 where 1 is the state id. Would that suit?

    Allan

  • WernfriedWernfried Posts: 35Questions: 10Answers: 0

    Yes, that's exactly what I was looking for. At the moment I create a custom button where I loop over all state properties and add each key-value as query parameter on the URL. A single query parameter (i.e the state id) would make much more sense.

    Wernfried

  • allanallan Posts: 66,088Questions: 1Answers: 11,012 Site admin
    Answer ✓

    Perfect - I think I can add that in fairly short order. I'm in the middle of some SearchPanes updates at the moment, but I'll look at implementing this and get back to you when it is ready.

    Allan

Sign In or Register to comment.