Page 1 of 1

Grid Persist State

Posted: Wed Apr 09, 2014 11:57 am
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".

Re: Grid Persist State

Posted: Wed Apr 09, 2014 6:49 pm
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.

Re: Grid Persist State

Posted: Thu Apr 10, 2014 3:49 pm
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!!!!

Re: Grid Persist State

Posted: Thu Apr 10, 2014 4:18 pm
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

Re: Grid Persist State

Posted: Thu Apr 10, 2014 9:24 pm
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.

Re: Grid Persist State

Posted: Fri Apr 11, 2014 9:54 am
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!!!!!

Re: Grid Persist State

Posted: Fri Apr 11, 2014 11:14 am
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.

Re: Grid Persist State

Posted: Fri Apr 11, 2014 11:48 am
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!!!!!

Re: Grid Persist State

Posted: Fri Apr 11, 2014 1:32 pm
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!