Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing custom editor (change the way in which custom cell types are being registered) #4254

Closed
SergeyShablenko opened this issue May 18, 2017 · 9 comments

Comments

@SergeyShablenko
Copy link

@SergeyShablenko SergeyShablenko commented May 18, 2017

After update it became impossible to write custom editor, i have an error

'handsontable.full.min.js:273 Uncaught (in promise) Error: You declared cell type "autocomplete2" as a string that is not mapped to a known object. Cell type must be an object or a string mapped to an object in Handsontable.cellTypes'
function autocomplete2(Handsontable) {
  const AutocompleteEditor = Handsontable.editors.AutocompleteEditor;
  const Autocomplete2Editor = AutocompleteEditor.prototype.extend();

  Handsontable.editors.Autocomplete2Editor = Autocomplete2Editor;
  Handsontable.editors.registerEditor('autocomplete2', Autocomplete2Editor);
  Handsontable.renderers.Autocomplete2Renderer = function Autocomplete2Renderer(instance, TD, row, col, prop, value, cellProperties) {
    // some code
  };
  Handsontable.renderers.registerRenderer('autocomplete2', Handsontable.renderers.Autocomplete2Renderer);

  Handsontable.Autocomplete2 = {
    editor: Handsontable.editors.Autocomplete2Editor,
    renderer: Handsontable.renderers.Autocomplete2Renderer,
    validator: function autocomplete2Validator(value, callback) {
       //some code
    }
  };

  Handsontable.cellTypes.autocomplete2 = Handsontable.Autocomplete2;
}(Handsontable);

My environment

  • Handsontable version: 0.32.0-beta1
  • Browser Name and version: Google Chrome Version 58.0.3029.110 (64-bit)
  • Operating System: Ubuntu 16.04 LTS
@pdemilly

This comment has been minimized.

Copy link

@pdemilly pdemilly commented May 19, 2017

Same problem here. It seems that expandType has changed and now instead of looking at handsonTable.cellTypes it is looking at a private variable _cellTypes2 (I guess from an import of CellTypes) which only contains the default cellTypes. So no way to add new cellTypes.

If you pass an object to type in the column definition you can go a little further but then it breaks further down as it requires types to be a string.

@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented May 19, 2017

Thank you for sharing guys.
I am marking this issue with the high priority.

@budnix

This comment has been minimized.

Copy link
Member

@budnix budnix commented May 19, 2017

Yep, there is definitively a bug. Currently, Handsontable doesn't operate on Handsontable object dynamically as it has happened before (in 0.31.1 and earlier).

To solve this issue I will implement a method which will be exposed to Handsontable.cellTypes.registerCellType. This solution is similar to other registerers such as Handsontable.renderers.registerRenderer and Handsontable.editors.registerEditor.

@krzysztofspilka

This comment has been minimized.

Copy link
Member

@krzysztofspilka krzysztofspilka commented May 19, 2017

We plan to update Handsontable to beta2(?) on Monday, May 22, with this fix included.

budnix added a commit that referenced this issue May 23, 2017
@budnix budnix assigned swistach and unassigned budnix May 23, 2017
@swistach swistach added this to the 0.32.0 milestone May 23, 2017
@swistach swistach assigned budnix and unassigned swistach May 23, 2017
@krzysztofspilka krzysztofspilka changed the title Writing custom editor Writing custom editor (change the way in which custom cell types are being registered) May 24, 2017
@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented May 24, 2017

@SergeyShablenko @pdemilly

Thank you for sharing this issue. I hope that the version 0.32.0-beta2 will meet your requirements. Can you check that one, please?

@budnix

This comment has been minimized.

Copy link
Member

@budnix budnix commented May 24, 2017

Hi guys,

We've released a fix in 0.32.0-beta2. In that release, we improved the API which gives you an ability to register a new custom cell type in the following way:

Handsontable.cellTypes.registerCellType('my-custom-select', {
  editor: MyCustomSelectEditor,
  renderer: MyCustomSelectRenderer,
  validator: MyCustomSelectValidator,
});

and that's it. In Handsontable configuration it will be available as:

new Handsontable(element, {
  data: data,
  columns: [{
    data: 'id',
    type: 'my-custom-select'
  }, {
    data: 'id2',
    editor: 'my-custom-select' // An alias for editor is automatically registered
  }, {
    data: 'id3',
    renderer: 'my-custom-select' // An alias for renderer is automatically registered
  }, {
    data: 'id4',
    validator: 'my-custom-select' // An alias for validator is automatically registered
  }, {
  }],
});

Can you confirm that everything works as expected with your codebase?

@SergeyShablenko

This comment has been minimized.

Copy link
Author

@SergeyShablenko SergeyShablenko commented May 26, 2017

Bug with editor fixed, but i have now next error, i assume it`s because my editor extends AutocompleteEditor
image
I mean, i have two custom editors, one extends TextEditor and works fine, another extends Autocomplete

@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented May 29, 2017

Hi @SergeyShablenko

thank you for a quick reply.

Could you send a demo or anything that will allow us to reproduce the issue?

@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented May 31, 2017

@SergeyShablenko

Please let me know about the issue or create a new topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.