Active States is incorrect when using Ajax and SearchBuilder

Active States is incorrect when using Ajax and SearchBuilder

desperadodesperado Posts: 159Questions: 33Answers: 4
edited February 7 in StateRestore

I can't create a test case for this because it is only happening to me when I use StateRestore stored by ajax.

I think only started recently after updating to the latest versions of SearchBuilder-1.3.1, StateRestore-1.1.0 and Buttons 2.2.2.

The problem I am having is if I create 3 saved states as follows
1) Default State - no search builder filter
2) Filter 1 - Define a rule in search builder to filter the data
3) Filter 2 - Define a different rule in search builder to filter the data a different way

Then if I select Default State, I get active states "Default State"
If I select Filter 1, I get active states "Default State, Filter 1"
If I select Filter 2, I get active states "Default State, Filter 2"

It only seems to consider the SeachBuilder data if there is some data present. If no data is present then it is consider a match even when the current state of SearchBuilder does contain data.

Here are screen shots of this happening in my system. These shots were taken without making any changes to the saved states.

When I select my "Default View" you can note that Only Default View is active.

When I select "Pending View", you can note that Pending View is active but so is Default View which is incorrect.

When I switch to "award filter", you can note that award filter is active but so is Default View again which is incorrect.

If I change the sorting and have no search builder data like this "test" case then it works as expected.

Then I added a SearchBuilder filter and test remains active (This is incorrect)

If I save that state, then the same issue happens with both being active even though one has a search builder filter and the other does not.

If I then select the test view and add a search builder with no conditions (not sure why this is allowed), and I save that state

Then that Saved State matches "test" which sort of makes sense since the results are the same but in reality what is in the saved state for SearchBuilder is in fact different. One has search builder data but it's "empty" the other has no search builder data.

If I look at what is stored in the DB I notice that in every case "searchBuilder":false is present which I think might be causing this issue.

Here is the saved data for "Default View"
{"time":1644261222297,"start":0,"length":10,"order":[[5,"desc"]],"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true},"columns":[{"visible":false,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}}],"ColReorder":[0,1,2,3,4,5,6,7,8,9,10],"childRows":[],"searchBuilder":{},"page":0,"stateRestore":{"isPredefined":false,"state":"Default View","tableId":"award-person-table","isPreDefined":false},"c":{"_createInSaved":true,"create":true,"creationModal":true,"i18n":{"creationModal":{"button":"Create","colReorder":"Column Order","columns":{"search":"Column Search","visible":"Column Visibility"},"name":"Name:","order":"Sorting","paging":"Paging","scroller":"Scroll Position","search":"Search","searchBuilder":"SearchBuilder","searchPanes":"SearchPanes","select":"Select","title":"Create New State","toggleLabel":"Includes:"},"duplicateError":"A state with this name already exists.","emptyError":"Name cannot be empty.","emptyStates":"No saved states","removeConfirm":"Are you sure you want to remove %s?","removeError":"Failed to remove state.","removeJoiner":" and ","removeSubmit":"Remove","removeTitle":"Remove State","renameButton":"Rename","renameLabel":"New Name for %s:","renameTitle":"Rename State"},"modalCloseButton":true,"remove":true,"rename":true,"save":true,"saveState":{"colReorder":true,"columns":{"search":true,"visible":true},"order":true,"paging":true,"scroller":true,"search":true,"searchBuilder":true,"searchPanes":true,"select":true},"splitSecondaries":["updateState","removeState","renameState"],"toggle":{"colReorder":false,"columns":{"search":false,"visible":false},"order":false,"paging":false,"scroller":false,"search":false,"searchBuilder":false,"searchPanes":false,"select":false},"preDefined":{}}}

Here is the data for "Pending View" which makes "Default View" active but should not.
{"time":1644261246795,"start":0,"length":10,"order":[[5,"desc"]],"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true},"columns":[{"visible":false,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}}],"ColReorder":[0,1,2,3,4,5,6,7,8,9,10],"childRows":[],"searchBuilder":{"criteria":[{"condition":"!=","data":"Pending Children","origData":"pendingChildren","type":"string","value":[" "]}],"logic":"AND"},"page":0,"stateRestore":{"isPredefined":false,"state":"Pending View","tableId":"award-person-table","isPreDefined":false},"c":{"_createInSaved":true,"create":true,"creationModal":true,"i18n":{"creationModal":{"button":"Create","colReorder":"Column Order","columns":{"search":"Column Search","visible":"Column Visibility"},"name":"Name:","order":"Sorting","paging":"Paging","scroller":"Scroll Position","search":"Search","searchBuilder":"SearchBuilder","searchPanes":"SearchPanes","select":"Select","title":"Create New State","toggleLabel":"Includes:"},"duplicateError":"A state with this name already exists.","emptyError":"Name cannot be empty.","emptyStates":"No saved states","removeConfirm":"Are you sure you want to remove %s?","removeError":"Failed to remove state.","removeJoiner":" and ","removeSubmit":"Remove","removeTitle":"Remove State","renameButton":"Rename","renameLabel":"New Name for %s:","renameTitle":"Rename State"},"modalCloseButton":true,"remove":true,"rename":true,"save":true,"saveState":{"colReorder":true,"columns":{"search":true,"visible":true},"order":true,"paging":true,"scroller":true,"search":true,"searchBuilder":true,"searchPanes":true,"select":true},"splitSecondaries":["updateState","removeState","renameState"],"toggle":{"colReorder":false,"columns":{"search":false,"visible":false},"order":false,"paging":false,"scroller":false,"search":false,"searchBuilder":false,"searchPanes":false,"select":false},"preDefined":{}}}

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 14,526Questions: 1Answers: 2,482

    Thanks for the post. Sandy is back in on Thursday and will take a nose then.

    Colin

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    @colin Thanks, I realized I could copy the ajax function example code and make a test case for this so here it is.

    http://live.datatables.net/jodumuqi/1/edit

    To see the issue take the following steps.
    1) Sort by Name and Save State as "Default State"
    2) Select "Default State" to make it active, notice active states are highlighted in green.
    3) With "Default State" active add a Search Builder Rule {Poisition = "Developer"}
    NOTE: notice that "Default State" remains active, this is incorrect.
    4) Save State as "Developer Filter"
    NOTE: notice Both "Developer Filter" and "Default State" are active
    5) Select "Default State" notice that the Search Builder condition is removed and the only active state is now "Default State". (Correct)
    6) Select "Developer Filter" notice that both "Developer Filter" AND "Default State" have become active. (INCORRECT)

    Seems strange to me that this only happens when using Ajax. why would the code be different for acting on the state between the two. I would think only the code to acquire/save the data would be different. It is an interesting issue.

    Thank you for your time looking at this issue.

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @desperado ,

    Sorry, but I'm not seeing that behaviour in your example. See this video. Maybe I'm doing something wrong?

    It is possible for 2 states to be active at the same time. Say you have a state that just searches for "developer" and nothing else, and another state that also searches for "developer" in the searchbox, but also has a SearchPanes filter for an "office". Both filters are being applied here, it's just that one is less detailed than the other.

    Thanks,
    Sandy

  • desperadodesperado Posts: 159Questions: 33Answers: 4
    edited February 10

    @sandy The mistake you made in your version of the test was that you created a searchBuilder instance by selecting it to show me that there was no condition set when you created your "Default" Saved State you can clear that state and save Default again to see the issue or follow the steps as I present them in the following videos.

    Here is a video of the correct steps.
    https://watch.screencastify.com/v/c0B3usE1ObvRkcCWePyI

    Here is exact same test not using ajax and the issue doesn't exist
    https://watch.screencastify.com/v/vV0jF059tr42SBqAREJS

    I also made this video to demonstrate that the behavior is different when using ajax if I use the "search" filter instead of the SearchBuilder.
    https://watch.screencastify.com/v/PqPivyHLwhs827N4nBwK

    I hope these videos help explain my position on this issue.

    Thanks,
    Ron

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @desperado ,

    Yes I can see your point there. There isn't going to be much we can do for predefined states that just apply certain aspects of the state. But for states like you create in the first video it should be possible to tell the difference.

    I've raised an issue internally (DD-2467 for my reference) and will report back here when there is an update. If not today then hopefully by the end of next week.

    Thanks,
    Sandy

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    @sandy Great thanks, I will keep an eye out for the update so I can install the changes.

    As always I appreciate your efforts! Cheers

  • desperadodesperado Posts: 159Questions: 33Answers: 4
    edited March 15

    @sandy Any update on this ?

  • colincolin Posts: 14,526Questions: 1Answers: 2,482

    I think this slipped through the cracks - the issue hasn't been progressed. I'll poke Sandy, he's back in again tomorrow,

    Colin

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @desperado ,

    Apologies for the delay in getting this done. With working part time I'm having to try to prioritise the bugs that come in, and this hasn't made it to the top of the pile yet. I'll take a look next week if not before.

    Thanks,
    Sandy

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    @sandy Thanks for the update. I understand, we all appreciate your effort!

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @desperado ,

    I've had a look at this today. Please see this modified version of your test case which should be working a bit better now.

    Now to decide active states, StateRestore will compare only the properties that exist on both states. This is assuming that there is atleast one property present within each object. If one object has no properties and the other does then the two are deemed not to match.

    Thanks,
    Sandy

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    @sandy looks good to me.

    I assume this requires changes you made to be released. Right? Not clear since you said you modified my test case I am wondering if that was how you fixed it.

    In other words....Do I need to modify my code to make this work or just pick up your new code? I am not clear on what you changed in my test case other then adding options to IDBStore.

  • kthorngrenkthorngren Posts: 17,238Questions: 25Answers: 4,091
    Answer ✓

    Looks like Sandy changed your test case to use the nightly versions of StateRestore and SearchBuilder.

    Kevin

  • desperadodesperado Posts: 159Questions: 33Answers: 4

    @sandy I hit answered:yes by mistake on kthorngren reply. :(

    @kthorngren, Thanks, I am aware he used nightly, I did notice that, but not sure if that was because of changes needed for this issue or not. You are likely correct but I would like to clarify so I am sure.

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @desperado ,

    Yes, Kevin is right. The changes are in the nightly builds and should be released soon.

    Thanks,
    Sandy

Sign In or Register to comment.