Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location.hash to local storage state key #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/model/model.defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ DataTable.defaults = {
try {
return JSON.parse(
(settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem(
'DataTables_'+settings.sInstance+'_'+location.pathname
'DataTables_'+settings.sInstance+'_'+location.pathname+location.hash
)
);
} catch (e) {}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ DataTable.defaults = {
"fnStateSaveCallback": function ( settings, data ) {
try {
(settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem(
'DataTables_'+settings.sInstance+'_'+location.pathname,
'DataTables_'+settings.sInstance+'_'+location.pathname+location.hash,
JSON.stringify( data )
);
} catch (e) {}
Expand Down
2 changes: 1 addition & 1 deletion old-tests/unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var oTest = {
{
var s = oTable.fnSettings();

localStorage.setItem( 'DataTables_'+s.sInstance+'_'+window.location.pathname, null );
localStorage.setItem( 'DataTables_'+s.sInstance+'_'+window.location.pathname+window.location.hash, null );
},


Expand Down
8 changes: 4 additions & 4 deletions test/options/Options/stateDuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('stateDuration Option', function() {
$('#example')
.DataTable()
.state.clear();
expect(sessionStorage['DataTables_example_' + location.pathname]).toBeDefined();
expect(sessionStorage['DataTables_example_' + location.pathname+location.hash]).toBeDefined();
});

dt.html('basic');
Expand All @@ -30,14 +30,14 @@ describe('stateDuration Option', function() {
.DataTable()
.state.clear();

expect(localStorage['DataTables_example_' + location.pathname]).toBeDefined();
expect(localStorage['DataTables_example_' + location.pathname+location.hash]).toBeDefined();

// The following test should fail - but it is passing due to
// https://sprymedia.manuscript.com/f/cases/394/API-call-state-clear-isn-t-clearing-the-state
// remove the test when that bug is fixed - it will cause the test to fail.
// The second test is just a failsafe to ensure it is behaving, so could optionally be removed
expect(sessionStorage['DataTables_example_' + location.pathname]).toBeDefined();
expect($.isEmptyObject($.parseJSON(sessionStorage['DataTables_example_' + location.pathname]))).toBe(true);
expect(sessionStorage['DataTables_example_' + location.pathname+location.hash]).toBeDefined();
expect($.isEmptyObject($.parseJSON(sessionStorage['DataTables_example_' + location.pathname+location.hash]))).toBe(true);
});
});
});