Show the selected option of a select ( select filter ) after refreshing
Show the selected option of a select ( select filter ) after refreshing
I'm using a select that filters a table.
Let's say I'm filtering cars based on their brands. when I choose for example "Mercedes" it filters the list which is good, and when I refresh it saves the state which is even better ( it shows only Mercedes' cars ).
The only issue is that when I refresh the chosen option displayed is "Select an option" even if the list is filtered for Mercedes.
I would like to know if it's possible update the displayed chosen option as well !
Here is the piece of code I used
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem('offersDataTables', JSON.stringify(oData));
},
"fnStateLoad": function (oSettings) {
return JSON.parse(localStorage.getItem('offersDataTables'));
}
This discussion has been closed.
Answers
You can use the initComplete callback to get the value from local storage and use it to set the selected value.
This is an example I wrote a while back for this sort of thing: http://live.datatables.net/lunopeba/1/edit . It uses the filters in the header and FixedHeader, but the key is that the value is selected when the filtering element is first created - this could be done in
initCompleteas @bindrid says (in fact it should be done there if you are using Ajax loaded data).Allan