How does State Restore order State names ?

How does State Restore order State names ?

desperadodesperado Posts: 159Questions: 33Answers: 4

Is it possible to get state restore to sort the states by name ?

my code puts the data into the map in order but this is an example of the result I get using testing names.

I would like ZZ Name to be last as it was when returned from my ajax call.

When I add a new state named "AB Name" I would like it to insert after "AA Name" but instead I get it inserted second to last which seems odd, last I could understand.

Then when I reload the page I get the following order.

For some reason "View 1" is stuck at the bottom no matter what I do.

This question has an accepted answers - jump to answer

Answers

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    I think the issue is that the data is passed to callback as a map of key=identifier and value=state.

    This is the code I use to generate that map. getViews returns the data in order of identifier as mentioned above.
    '''
    if (data.action === 'load') {
    let url = _rcoiBaseUrl + "dataTablesView/getViews";
    $.get(url,function (data,status) {
    let cbData = {};
    for (let i = 0; i < data.length; i++) {
    // Convert back from the string created when saving
    cbData[data[i].identifier] = JSON.parse(data[i].state);
    }
    // Load states into StateRestore
    callback(cbData);
    });
    }
    '''

    The really strange part is "View 1" seems to always be the name at the bottom. I wiped my DB and created 4 views.

    I created "ABC First View" first, ZZ Second View second, I created "View 1" next and then "Number 2"

    Once again, only "View 1" is sticking to the bottom. So weird.

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    I think I figured it out but I don't understand why StateRestore Does this.
    It seems to place states using the "Default" naming at the bottom.

    The sort order seems to be
    Non-Default Names - in order provided
    Default Names - last sorted by identifier

    My default name was "View %d". All "View %d" based names are always at the bottom.

    I changed my default name as a test to "XView %d" and now "View %d" names are working and "XView %d" names are sticking to the bottom.

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @desperado ,

    We had implemented an algorithm that would sort states based off of the default name's state number - but on reflection we think it makes more sense to just sort alphabetically. I've made a change for this that will be available in the next StateRestore release which we hope will be in the next few weeks. Until then you can access the fix from the nightly builds.

    Thanks,
    Sandy

Sign In or Register to comment.