Grid Persist State

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
anthonyb
New User
Posts: 2
Joined: Thu Oct 21, 2010 5:45 pm
First Name: Bruce
Last Name: Anthony
Company Name: The State Bar of California
Phone: 415 538-2423
Address 1: 180 Howard Street
City: San Francisco
State / Province: California
Zip / Postal Code: 94105
Country: United States
Contact:

Grid Persist State

Post by anthonyb »

I see that any allowed user changes to grid columns are reset when the display file is recompiled. Is there a way to programmatically reset a specific user setting back to the compiled version? I was thinking of having a button on the screen that would say something like, "Reset to Default Layout".
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Grid Persist State

Post by Scott Klement »

Recompiling the display file should not reset any settings... unless you did something like change the record format of the grid, or the lib/obj name of the display file.

The 'persist state' properties are stored in your browsers "local storage". This is a feature of HTML5 that lets applications store data inside the browser. We generate a "key" that we save it under... the key is "pui-grid-LIB-FILE-RECFMT". So for example, if you have a subfile with record format MYSFL locaated in a display file named THESCREEN in the QGPL library, then the key would be "pui-grid-QGPL-THESCREEN-MYSFL".

Once you know the key, you can write a one-liner JavaScript that will clear the settings from the local storage. Maybe put a button on the screen, and set the button's "onclick" property to something like this:

Code: Select all

localStorage.clear("pui-grid-QGPL-THESCREEN-MYSFL");
This will wipe out the persistent settings for that grid.

Unfortunately, there is no easy way to wipe out the individual settings (col sequence, sort sequence, column width) individually... they are all stored together in a JSON string that's kept in the localStorage. You'd have to read it and parse it and then re-generate a new localStorage value.

I will mention this issue to the other developers, maybe we can add this as a feature to the product to make it simpler in the future.
emhill
Experienced User
Posts: 116
Joined: Wed Sep 05, 2012 11:14 am
First Name: Eric
Last Name: Hill
Company Name: Integrated Corporate Solutions
Phone: 256-760-8239
Address 1: 501 S Wood Avenue
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Contact:

Re: Grid Persist State

Post by emhill »

What great timing!!! Thanks Scott. We were just about to ask this very question on here. Been fighting with this for a couple of days now.

Appreciate all you do!!!!
anthonyb
New User
Posts: 2
Joined: Thu Oct 21, 2010 5:45 pm
First Name: Bruce
Last Name: Anthony
Company Name: The State Bar of California
Phone: 415 538-2423
Address 1: 180 Howard Street
City: San Francisco
State / Province: California
Zip / Postal Code: 94105
Country: United States
Contact:

Re: Grid Persist State

Post by anthonyb »

Scott,

The following,

localStorage.clear("pui-grid-QGPL-THESCREEN-MYSFL");

works very well for me. It's unfortunatel that the library name has to be qualified but I can work around this issue.

Thanx again,

Bruce
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Grid Persist State

Post by Scott Klement »

I agree about the library. The library name does need to be there, since it's possible to have display files with the same names in more than one library, and therefore it needs to keep track of the settings separately.

However, I agree that you should not have to hard-code this stuff. Profound UI obviously knows which library/object is on the screen, we should provide a way to clear it without you needing to hard code that information.

Again, I will mention this to the other developers, I'm sure we can come up with a better solution. Right now, calling localStorage.clear() is just a workaround.
emhill
Experienced User
Posts: 116
Joined: Wed Sep 05, 2012 11:14 am
First Name: Eric
Last Name: Hill
Company Name: Integrated Corporate Solutions
Phone: 256-760-8239
Address 1: 501 S Wood Avenue
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Contact:

Re: Grid Persist State

Post by emhill »

Scott,

I would like to check to see if there is anything in the localstorage and hide/show a reset button based on if there is anything there or not. Would this script handle it?

if(localStorage.getItem("pui-grid-QGPL-THESCREEN-MYSFL")) {
<show button>
}
else {
<hide button>
}

**** Edit ****
This seems to work great. Another question. I have the above code in the onload event and it is working fine. But let's say I move a couple of the grid columns. Is there a way to know right away that I have done that so I can immediately show the button to reset the grid? As I have it above it will only show after the user makes a change and clicks Submit.

Thanks!!!!!
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Grid Persist State

Post by Scott Klement »

I can't think of an easy way to make the button appear as soon as the user moves a column...

I guess you could put it on a timer, have it check every second or so, and if something is set, make the button appear... but IMHO, that's overkill.

I would just always have the button there... so what if they click it when there's nothing to reset? no harm done.
emhill
Experienced User
Posts: 116
Joined: Wed Sep 05, 2012 11:14 am
First Name: Eric
Last Name: Hill
Company Name: Integrated Corporate Solutions
Phone: 256-760-8239
Address 1: 501 S Wood Avenue
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Contact:

Re: Grid Persist State

Post by emhill »

Scott,

I placed this in my onrowmouseout event for the grid:

=================================================================
var localcheck = "pui-grid-" + get("PGMLIB") + "-OE0024FM-SCR03";

if(localStorage.getItem(localcheck)){
applyProperty("ResetGrid", "visibility", "visible");
applyProperty("ResetLabel", "visibility", "visible");
}
else{
applyProperty("ResetGrid", "visibility", "hidden");
applyProperty("ResetLabel", "visibility", "hidden");
}
=================================================================
Seems to work ok. A little delay until the user moves the mouse out of the row but I think it will work.

Thanks!!!!!
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Grid Persist State

Post by Scott Klement »

That will work, but it occurs when the user moves the mouse out of a row... if that's what you wanted, great!
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests