DataTables / StateRestore

StateRestore extension for Datatables
Other
3 stars 3 forks source link

Need the ability to rename the saved data to local storage like stateSave allows #6

Closed gouldner closed 2 years ago

gouldner commented 2 years ago

While trying to test in live.datatables.net and/or JSfiddle I was having issues with saved states across test cases.

Then I realized that is because local storage is managed at the url level not the context level.

For example the first state is created in local storage as "DataTables_stateRestoreState 1/runner" under live.datatables.net

If I cone the test case the new test case still has the saved case from the previous.

This means in my project which is located at mymachine.hawaiil.edu when I create three different data tables, under different contexts, such as mymachine.hawaii.edu/awards, mymachine.hawaii.edu/disclosures They are going to share the same saved storage space for named states.

This issue is resolved in saveState using the stateSaveCallback and stateLoadCallback which I have currently implemented for all of my datatable pages.

        stateSaveCallback: function(settings,data) {
            localStorage.setItem( "DataTables_awardDashboard" + _currentUser, JSON.stringify(data) )
        },
        stateLoadCallback: function(settings) {
            return JSON.parse( localStorage.getItem( "DataTables_awardDashboard" + _currentUser) )
        }

I think something like this needs to be implemented for StateRestore unless I am missing something in my testing and analysis.

I think the condition is best described rather than demoed but this is the test case I used just in case. http://live.datatables.net/hodapemo/1/edit

PS: sorry for creating so many issues. Hope that's OK and it is helping.

SandyDatatables commented 2 years ago

Hi @gouldner ,

This is happening on the live page because the table is running within an iframe which across all of the live pages has the same name. This won't be an issue on your actual webpage - unless you employ a similar technique. You can see this is not going to be the case by trying some of the examples on the Datatables website.

I'm going to mark this as an enhancement internally (DD-2399 for my reference) and will report back here when there is an update.

Thanks, Sandy