Page 1 of 1

Reset show/hide columns to pre-defined default

Posted: Mon Jan 13, 2020 10:38 am
by nbush78
We're currently using the onload event of the record format to set default show/hide columns if no local storage key/value exist for a grid. This works well. The issue is when the reset option is taken on the grid. I would like to use the onfilterchange event of the grid to re-execute the onload event of the record format to re-apply the defaults. Currently I have copied the same code from onload and have it in the onfilterchange as well. But now have two places to update if we want to change the default show/hide columns.

Re: Re-execute onload event

Posted: Mon Jan 13, 2020 11:53 am
by nbush78
So onfilterchange isn't the best solution. Is there any event that triggers after reset?

Re: Re-execute onload event

Posted: Mon Jan 13, 2020 1:09 pm
by nbush78
Solution so far:
Using External JS (Screen Level)
Record Format onLoad event references the external js.
Grid onFilterChange references the external js and passes a value to designate that it is executing from onFilterChange

External JS checks to see if the local storage for the persistant state is null or if execution from onFilterChange
If so, set grid defaults (currently just show/hide columns)

Issue is onFilterChange was not meant for this. If not a separate event then just a variable that I could pass to the ExternalJS from the onFilterChange event to designate that the onFilterChange was executed because of reset vs a true filter change. Vurrently I check for this in the OnFilterChange Event via:

Code: Select all

try {
  var reset = arguments.callee.caller.caller.caller.arguments[0].target.innerText;
}
catch(err) {
  reset = '';
}
if (reset == 'Reset') {
  uniqueGridID_DefaultView(reset);
}

Re: Re-execute onload event

Posted: Wed Jan 15, 2020 5:50 pm
by Scott Klement
I don't think anyone has tried to do this before? Or, at least, I haven't run across it.

I do have an idea, though... you could call the grid's getFilter() method for each column (in a loop.) This function returns null if no filter was set, so you could use this to determine if nothing has been filtered. This would allow you to pass a flag to your function so that it could tell that there aren't any filters.