diff --git a/docs/example-widget-sort-to-hash.html b/docs/example-widget-sort-to-hash.html index 4dac26fc..55a8853b 100644 --- a/docs/example-widget-sort-to-hash.html +++ b/docs/example-widget-sort-to-hash.html @@ -42,6 +42,9 @@ sort2Hash_directionText : [ 0, 1 ], // default values // if true, override saveSort widget sort, if used & stored sort is available sort2Hash_overrideSaveSort : true, // default = false + // if true, hash changes are not saved to browser history + sort2Hash_replaceHistory : false, + sort2Hash_encodeHash : null, /* how to use encodeHash sort2Hash_encodeHash : function( config, tableId, component, value, rawValue ) { @@ -209,6 +212,17 @@ if true, the hash sort will override any stored sort (saveSort widget). + + + false + Change how the browser history is managed (v2.29.0) +
+

If true, all hash changes are not saved to browser history, so when the user presses the back arrow, they will be returned to the previous page.

+ If false, all hash changes are preserved in the browser history, so when the user presses the back arrow, the hash will show the previous state, but the table won't update unless the page is refreshed. +
+ + + null diff --git a/js/widgets/widget-sort2Hash.js b/js/widgets/widget-sort2Hash.js index 49f96752..1af47bfe 100644 --- a/js/widgets/widget-sort2Hash.js +++ b/js/widgets/widget-sort2Hash.js @@ -226,18 +226,26 @@ str += value; }); + var hashChar = wo.sort2Hash_hash; // Combine new hash with any existing hashes - var hashChar = c.widgetOptions.sort2Hash_hash; - var newHash = ( ( window.location.hash || '' ).replace( hashChar, '' ).length ? hash : wo.sort2Hash_hash ) + str; - var baseUrl = window.location.href.split(hashChar)[0]; - // Ensure that there is a leading hash character - var firstChar = newHash[0]; - if (firstChar != hashChar) { - newHash = hashChar + newHash; - } + var newHash = ( + ( window.location.hash || '' ).replace( hashChar, '' ).length ? + hash : hashChar + ) + str; - // Update URL in browser - window.location.replace(baseUrl + newHash); + if (wo.sort2Hash_replaceHistory) { + var baseUrl = window.location.href.split(hashChar)[0]; + // Ensure that there is a leading hash character + var firstChar = newHash[0]; + if (firstChar != hashChar) { + newHash = hashChar + newHash; + } + // Update URL in browser + window.location.replace(baseUrl + newHash); + } else { + // Add updated hash + window.location.hash = newHash; + } } }; @@ -250,6 +258,7 @@ sort2Hash_headerTextAttr : 'data-header', // data attribute containing alternate header text sort2Hash_directionText : [ 0, 1 ], // [ 'asc', 'desc' ], sort2Hash_overrideSaveSort : false, // if true, override saveSort widget if saved sort available + sort2Hash_replaceHistory : false, // if true, hash changes are not saved to browser history // this option > table ID > table index on page sort2Hash_tableId : null,