Ajax loaded states from StateRestore not included in `activeStates()`?
Ajax loaded states from StateRestore not included in `activeStates()`?
I'm sorry, I don't have a way of offering a live example on this, but I'm hopeful if I can explain what's happening, you might have some suggestions.
I am using stateRestore
via ajax to my server for storing states (via savedStates
) . On page load, those states are being loaded via the same ajax call that gets the table data (ajaxTableData.php
script). I have no problem saving, renaming, removing, or even loading the states. This part all works correctly. You can see via the image below, I have my two saved states appearing.
Where I'm running into issues is after the states are loaded, they don't appear to be considered as part of stateRestore.activeStates()
. I can click on one of the saved states and the table will adjust accordingly, but the button doesn't change color to indicate it's selected. I'm using Foundation, so the button should turn gray if it's, indeed, the active state or remain blue if it's inactive. Where it becomes interesting is if I were to create a new state, which also gets saved to my DB, that new state is now considered part of stateRestore.activeStates()
, but only until I reload the page, then it behaves like the other already saved states and is no longer included in stateRestore.activeStates()
.
My question is how do I get ajax loaded states to be included in stateRestore.activeStates()
? I'm relying on activeStates()
to do some other things like changing the text of the savedStates
button and the table caption based on the selected state.
Thanks for your help!
Replies
I think we're going to need to see this. In this example, which sounds like what you're doing though admittedly not Foundation, it seems to be working as expected. Here, Foundation styling is working too, so I suspect combined they'd also be behaving.
If you could link to your page, or create a test case, we can take a look. 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.
Colin
Thanks, Colin.
You can actually see the issue in your example. I was only pointing out Foundation because it is very prominent when an active state has been selected (e.g., gray button).
But in that example, here are the steps to follow:
1. Create two or three states.
2. Select one of the states and you should see that it's highlighted as the active state.
3. Reload the page (your saved states should still be present)
4. Click on one of the states. You should see that it's not highlighted as an active state.
5. Create a new state. You should see that new state is highlighted, but if you go to click one of other states pulled in on the reload, they won't highlight to indicate they're the active state.
This is the same behavior I'm experiencing.
Any ideas on what's going on? I'm more familiar with php than I am with JS, so I'm afraid I can't be much help in figuring out where it's coming from, but I suspect the ajax is running before stateRestore is actually active so the states are being added before they're recognized by stateRestore.
Thoughts?
Thanks,
Tanner
Hi Colin,
Any thoughts on this issue? I think it's related to https://datatables.net/forums/discussion/73990/update-button-not-firing-with-extend-savedstates#latest, which I commented on around the same time.
Thanks for your help!
Take care,
Tanner
Hi Colin,
Any updates on this issue? As I wrote previously and also in another thread the issue I'm having appears on your example, so it's not isolated to my specific situation.
Thanks for your help!
Take care,
Tanner