Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82040

Restoring values using localStorage object

$
0
0
I am using an external multi-select filter on some grids and for my purposes after leaving the page and coming back, I know that the filter values I used still exist but how to get them to populate the select again. So this is what I did and it could be used for anything.

The localStorage addition really helped a lot, thanks!

Below you will see the fnStateLoad and I added in the dataFN and other variable below it. if you reload and it is null it does nothing. I used it to find the column, this being 2, and grab the data to set the select box in a later function in the fnDrawCallback. I can elaborate more but basically if you are using localStorage, this allows you to parse the object and put back items that are not a part of the datatables object.

"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
	localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) );
},
"fnStateLoad": function (oSettings) {
	//look for the saved info for the Filter boxes. 
	//if find match, then save it.
	dataFN = JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname));
	if (dataFN != null) {
		yourvariablename_sSearch = dataFN.aoSearchCols[2].sSearch;
	}			
        return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) );
},	

I can show all the code I did but this is the core of it. Hope it helps.

Enjoy.

Viewing all articles
Browse latest Browse all 82040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>