YADCF - how to get status from LocalStorage if data is filtered?
YADCF - how to get status from LocalStorage if data is filtered?
matissg
Posts: 63Questions: 15Answers: 0
I'm using YADCF externally trggered and would like to notify users if data is filtered. In addition I'm using stateSave: true
for my DataTable. At the moment in my Local Storage I see DataTables has saved yadcfState
. When I do
"stateLoaded": function (settings, data) {
console.log( 'Saved filter was: '+ data.yadcfState );
}
I get back [object, Object]
.
Is there a way I can get back some value wich tells me if there is any filtering ON for my table? Then I could do checking and notify a user that "Filter is ON!".
Thank you for any hint.
This discussion has been closed.
Answers
Hi @matissg ,
YADCF is a third-party extension, so would be worth asking on their site or SO. If it's storing state in the
stateSave
object, then you could try seeing what's in thatdata.yadcfState
, as there might be some clues in there. Tryconsole.log(JSON.stringify(data.yadcfState))
, that'll display the object.If no joy, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
@colin Thank you, it looks like there is no values saved into
yadcfState
, however my filter values are saved in DataTablecolumns
. So I besically have to do something like in this answer, I believe.@colin Looks like final solution could be something like this:
For externally triggered YADCF filtering add this as well:
For anyone who is interested, what happens here is this:
1. when DataTable is opened, we can use stateLoaded to retrieve info about saved state of the table, including any filtering
2. we iterate over saved state of Columns from LocalStorage and count if there is any where filter is on
3. if there is at least one filter on, do something (e.g., show notice), else do something else, e.g., remove notice
4. in case there is externally triggered filtering panel with "Filter"/"Clean" buttons, add lines to add/remove notice as well
I hope this helps someone.
Hi @matissg ,
Yep, I'd agree with that
Cheers,
Colin
@colin Minor tweak to have externally triggered filtering fields appear when there is no LocalStorage for DataTable:
We need this for situations when there is nothing in LocalStorage for a table.