SlickGrid icon indicating copy to clipboard operation
SlickGrid copied to clipboard

explicitInitialization = true does not work with hidden parents

Open pietermartin opened this issue 4 years ago • 5 comments

When explicitInitialization=true and the grid is inside a invisible parent, then it leaks var cssShow = { position: 'absolute', visibility: 'hidden', display: 'block' }; into the dom. This in turn breaks other functionality. In our case we are placing the grid inside a bootstrap modal, but the leaked style settings breaks bootstrap's functionality.

pietermartin avatar Jan 17 '21 17:01 pietermartin

Slickgrid requires a visible parent to initialise, so before initialising, it makes an invisible parent object visible with an absolute position off the screen by applying these CSS settings. it caches the settings and replaces them with the original settings after initialisation is complete.

Regardless of your modal settings, it will still be necessary for this process to occur in order to initialise the grid. However we could possibly make a change to allow you to use different settings than the cssShow settings above, which are currently baked in.

If the original settings are not being restored correctly, then that is a bug, and I can fix if you can diagnose and provide a one-page test case.

6pac avatar Jan 18 '21 01:01 6pac

The original settings do not get a chance to be restored because the init method checks for the explicitInitialization flag.

if (!options.explicitInitialization) {
    finishInitialization();
}

The finishInitialization does not fire which means that slickgrid leaves part of dom outside its container in a altered state. Later I indeed call grid.init() which invokes finishInitialization() but by that time its too late as the altered dom has interfered with other components's functionality.

I'll post an example later today.

pietermartin avatar Jan 18 '21 04:01 pietermartin

Actually, that description is fine, don't worry about an example. Strange that we haven't run across this issue before.

The easiest solution I can think of is to provide an option flag to suppress the css caching entirely and expose it as methods for you to call at appropriate points (or of course, optionally use your own alternative method). Would this work for you?

6pac avatar Jan 19 '21 01:01 6pac

Yes that will work for us, thanks.

pietermartin avatar Jan 19 '21 05:01 pietermartin

OK, have added options.suppressCssChangesOnHiddenInit, and exposed cacheCssForHiddenInit and restoreCssFromHiddenInit as public methods. Note that there is code both in stage 1 init and stage 2 init (finishInitialization()) that requires the parent to be visible. So you are going to need to take care of that in an outer code block. I have a sneaking suspicion that these changes may in the end be shown to be not necessary, But please, prove me wrong!

Note that these have been committed to the codebase, but I haven't done a public release at this point until this is tested and you're happy with it.

6pac avatar Jan 19 '21 13:01 6pac

it looks like a code change was implemented in SlickGrid but no feedback was provided, I think it's safe to close. Please provide more details if the problem occurs

ghiscoding avatar Sep 28 '23 03:09 ghiscoding