How to set default global configuration options

Hey, I am sorry if this is a stupid question. I am having a hard time understanding how I can set default configuration options globally within my project for all instances of handsontable.

What I am trying to set,

imeFastEdit: true

What I have tried so far,

  1. Directly changed the default in handsontable.js => did not work
  2. Set it alongside my definition in individual instances => worked
  3. Set it in a common.js script to overwrite the default

Here is what I tried doing in approach 3,

Handsontable.hooks.add('afterInit', function () {
    console.log("hot", this);
    if (typeof Handsontable !== 'undefined') {
        Handsontable.DefaultSettings = Object.assign({}, Handsontable.DefaultSettings, {
            imeFastEdit: true,
            licenseKey: 'non-commercial-and-evaluation'
        });
        console.log('Handsontable library is loaded', Handsontable);
    } else {
        console.error('Handsontable library is not loaded');
    }
});

In the above snippet, the weird part is it sets the imeFastEdit (and licenseKey for faster debugging if it works or not) but it still does not work. What I mean is the console.log will still show the alert saying license key is not set and the imeFastEdit wont work

For reference here is my example definition,

hot = new Handsontable(container, {
	//licenseKey: 'non-commercial-and-evaluation',
	data: data,
    themeName: 'ht-theme-horizon',
    language: 'ja-JP',
	manualRowResize: true,
	rowHeaders: true,
	rowHeights: 50,
	className: 'htMiddle',
	renderer: detailRenderer,
    //imeFastEdit: true,
	fillHandle: false,
	preventScrolling: false,
	hiddenColumns: {columns: [0,9,10,11,12, 13, 14, 15, 16, 17, 18, 20, 21]},
	filters: true,
	dropdownMenu: ['filter_by_condition', 'filter_by_value', 'filter_action_bar'],
	columns: [惻惻惻],
    manualColumnResize: true,
    manualRowResize: true,
    renderAllRows:true,
    stretchH: 'all',
	afterChange: getChangedRows,
	afterGetRowHeader: function(col, TH) {
		TH.className = 'htMiddle'
	},
	cells: function (row, col) {
		var cellProperties = {};
		cellProperties.renderer = detailRenderer;
		return cellProperties;
		
	}
});

Other ways I tried for approach 3 are:

Handsontable.hooks.add('afterInit', function () {
        if (typeof this.getSettings().imeFastEdit === "undefined") {
            this.updateSettings({ imeFastEdit: true });
            console.log("imeFastEdit has been set to true for instance:", this);
        }
    });
    Handsontable.hooks.add('afterInit', function () {
        this.imeFastEdit = true;
        console.log("imeFastEdit is set to true for instance:", this);
    });

These did not work as well.
I am quite confused as to what the issue is that is causing it to not work properly, if it is something with the way I am defining it or maybe in the syntax itself?
Any help is appreciated, thanks

Hi @param556

Iā€™ll do my best to help.

If the imeFastEdit: true is the only setting that has to be added it might be easier to do it manually. However, of youā€™d like to build an initial setup and then make it grow with other default settings I may recommend

  • setting up a new instance with a settings variable. Where let settings = { imeFastEdit: true}
  • calling instance.updateSettings() to load settings per given instance

Hi @aleksandra_budnik
First off, thank you for your response. I did initially think of just having imeFastEdit setting but now that I think of it, it makes more sense to have a lot more settings set as default based on our workspace settings like language, theme, headers, etc.

Secondly, the method you mentioned with using instance.updateSettings() I did try a similar approach to that with this.updateSettings({ imeFastEdit: true }); and the setting gets updated but it does not apply itself to the instance.

I will try to come up with a demo as early as possible and send it to you (coz its TGIF here)

Great. Thank you. i will then wait for the demo.

Hey @aleksandra_budnik
I tried this demo and got the problem to show up, please check.
note that I have simulated the file called global.js as a project wide global JS script and the script.js is the normal index fileā€™s JS script.
What I have tried is removing the options license-key and imeFastEdit from the handsontable definition and trying to pass it from the global script, which is not working. Please tell me if there is something wrong with the way I am doing it or something else is affecting it

Hi @param556

I checked your demo and it looks like the whole function in your global.js file isnā€™t loaded at all as it throws an error on the first line. In general what my colleague meant is to just use this method: https://handsontable.com/docs/javascript-data-grid/api/core/#updatesettings

Hey @adrian.szymanski
Apologies for that syntaxial error, just an accident due to over use of jQuery.
I have made the change you recommended and yet the settings wouldnā€™t get updated.

The method you mentioned needs to have the instance defined. In my case I donā€™t know if a particular page where this code snippet is being called has an handsontable instance.

Iā€™m sorry if I am not able to explain the issue properly,
What I am wanting to achieve is that I can put a generalized piece of code in my global script (included project-wide) which checks for the existence of a single or multiple handsontable instance in a page and overrides their settings with the default settings mentioned in the global script.

To achieve this I tried using the various hooks like afterInit and methods like getSettings and updateSettings but could not get it to work. That is why I want to know if there is any specific restriction on how the configuration options can be overridden and or if there is any demo where such an use-case is replicated then it would be helpful.
Thanks!

Hi @param556

Thank you for the explanation. I recreated such scenario in the simplest environment and the updateSettings works just fine for overriding the existing settings of the chosen instance. You can check it here: https://jsfiddle.net/s6go7x9q/

Hey @adrian.szymanski,
Thanks for the demo, I looked at it and I see that the issue still persists. I have marked in the image below, (marked in red is hot_02)

Do you see how colHeaders and rowHeaders are getting applied but not the licenseKey.
Is it possible that such a case would exists for imeFastEdit too?
That only a certain set of configuration options can be overridden from outside the definition of the grid.
If that is the case, could you please share the list of settings that can be overridden?

Hi @param556

Youā€™re right, I didnā€™t notice that. I checked our internal issues and itā€™s also true that imeFastEdit state was being reset while updating the settings but it was fixed in the latest release, 15.0. Iā€™ll do additional testing to check that.

1 Like

Hi @adrian.szymanski
Apologies for the late response. Could you confirm the fix for 15.0 because I found the issue when using 15.0.
I have not tested the old versions. It is not an super urgent issue as I have made the configurations within the grid definition for now. But do let me know once it is resolved.
Thanks and Cheers!

Hi @param556

Yes, the issue fix was released even before that, in version 14.4. Iā€™ll do more testing and update you once I find the source of this problem. It is also be possible that the problem returned.

1 Like

Hi @param556

if the issue that was specified as to be fixed in v14.4 is still replicable for you in v15.0.0 it might be related to one of the following

  • you have some extra logic applied that alters the behavior
  • issue is not fixed on a given device/browser
  • you use some browser addons that are interacting with the table
  • you are using keyboards that were not tested

Could you please contact us at support@handsontable.com, share a complete

  • demo
  • system/browser setting
  • steps to replicate the issue (or possibly a video reproduction)
  • details about used keyboard