Posted 13 September 2020, 6:51 pm EST
Hi all,
I am currently working on a quite complex Angular 10 application with many FlexGrids, which should be generated from some meta information coming from the backend. This means, the cells of the grid should display ComboBoxes, Autosuggestions, depending on the meta data coming from the backend.
I have implemented all of this with ng-templates (+ wjFlexGridCellTemplate) and inside of those ng-templates I used ng-containers with ngSwitch to select the right template depending on the meta data (if it should be a dropdown, autosuggestion and so on…)
Unfortunately, rendering takes quite some time with those complex checks inside of the ng-template. Therefore I started using a CustomCellFactory for my requirement.
This is how my updateCell function looks like:
public updateCell(p: GridPanel, r: number, c: number, cell: HTMLElement, rng?: CellRange, updateContent?: boolean) {
switch (p.cellType) {
// regular cells
case CellType.Cell:
// get cell geometry
super.updateCell(p, r, c, cell, rng, false);
switch (dataType) {
case 'dropDown':
this.createGenericDropdown(p, r, c, cell);
break;
case 'string':
this.createDefaultCell(p, r, c, cell);
break;
default:
break;
}
break;
...
}
}
And then for example, creating the generic Dropdowns:
public createGenericDropdown(panel: GridPanel, rowIdx: number, colIdx: number, cell: HTMLElement): void {
const supplierId = this.headerDefinitions[colIdx].supplierId;
const itemsSource = panel.grid.itemsSource;
const combo = new ComboBox(document.createElement('div'), {
displayMemberPath: 'name',
selectedValuePath: 'name',
selectedValue: itemsSource[rowIdx].map[supplierId],
itemsSource: itemsSource[rowIdx].propertyMeta[supplierId].dropDownValues
});
cell.innerHTML = '';
cell.appendChild(combo.hostElement);
panel.rows[rowIdx].height = 36;
}
The rendering already seems to be a bit faster, but now I am a bit stuck with handling the editing of the grid. In the ng-templates I used the (lostFocus) event to trigger some save action. And again, depending on some further meta information I had to use different save actions in the component where I have implemented the FlexGrid.
Now coming to my questions:
- How can I bind a function from the ComboBox lostFocus event inside of another component?
- Instead of using a ComboBox, I would prefer using a DataMap. But I noticed that binding a DataMap to a Column in the updateCell function is causing a re-rendering loop of the cell.
Do you have any other examples of more extended CellFactory usage than the demo for the CustomCellFactory?
As it doesn’t even show how the editing works with custom cell factories, it is a bit too basic in my opinion.
Thank you
Pascal