Flexgrid with CellFactory

Posted by: metrik on 19 July 2018, 1:16 am EST

    • Post Options:
    • Link

    Posted 19 July 2018, 1:16 am EST

    Hello,

    In our project we’re using Wijmo from NPM packages. This blocks us from using native AngularJS 1 integration since it’s not yet supported.

    So we are trying to achieve similar behavior by creating our own CellFactory:

    
    import { CellFactory, GridPanel, CellRange, CellType, Column, Row } from "wijmo/wijmo.grid";
    
    export class NgCellFactory extends CellFactory
    {
        private _cellsTemplates: _.Dictionary<string> = {};
        private _linkFns: _.Dictionary<ng.ITemplateLinkingFunction> = {};
        private _scopes: _.Dictionary<ng.IScope> = {};
    
        constructor(private $scope: ng.IScope, private $compile: ng.ICompileService)
        {
            super();
        }
    
        public addCellTemplate(name: string, template: string)
        {
            this._cellsTemplates[name] = template;
        }
    
        public updateCell(panel: GridPanel, row: number, col: number, cell: HTMLElement, rng?: CellRange, updateContent?: boolean)
        {
            if (panel.cellType !== CellType.Cell)
            {
                super.updateCell(panel, row, col, cell, rng, updateContent);
                return;
            }
    
            const colId = (<Column>panel.columns[col]).binding;
            const cellId = row + "_" + colId;
    
            if (!this._linkFns[colId])
            {
                this._linkFns[colId] = this.$compile(`<div>${this._cellsTemplates[colId]}</div>`);
            }
            if (!this._scopes[cellId])
            {
                this._scopes[cellId] = this.$scope.$new();
                this._scopes[cellId]["$row"] = panel.rows[row];
                this._scopes[cellId]["$col"] = panel.columns[col];
                this._scopes[cellId]["$item"] = (<Row>panel.rows[row]).dataItem;
            }
    
            const clone = this._linkFns[colId](this._scopes[cellId], clone => { });
            if (cell.firstChild && clone[0] !== cell.firstChild)
            {
                cell.replaceChild(clone[0], cell.firstChild);
            }
            else if (!cell.firstChild)
            {
                cell.appendChild(clone[0]);
            }
            super.updateCell(panel, row, col, cell, rng, false);
        }
    }
    
    

    I have written the “my-grid…” directives myself trying to follow how it looks in your native integration.

    This CellFactory seems to do the right thing - enabling to provide custom Angular templates into grid cells.

    The problem with it is cells don’t get immediately transformed. For example, if I have the following template:

    
    <my-grid items-source="data">
        <my-grid-column header="Country" binding="country">
          <my-grid-cell-template>
                {{$item.country}}
            </my-grid-cell-template>
        </my-grid-column>
    </my-grid>
    
    

    after running the code I still see for some time “{{$item.country}}” instead of “US”. When I scroll the grid the same happens - templates are flickering.

    Have you got any idea of how to get rid of that flickering? When looking at your native integration everything works without flickering…

  • Posted 19 July 2018, 11:27 pm EST

    Hi,

    After looking at the code snippet provided, as we understand, you are trying to create your own directive cell-template directive same as wjFlexGridCellTemplate.

    However, it will not be possible to provide with a solution without a sample of your implementation so can you please provide a simplified sample so that we can look into it.

    Also, we would recommend you to download the wijmo files along with angular interop file and include them in your project.

    P.S. If you are using webpack for bundling modules then you may refer to the following thread which discusses about wijmo+angularjs+webpack setup.

    https://www.grapecity.com/en/forums/wijmo/angularjs--webpack-setup

    ~Manish

  • Posted 23 July 2018, 11:30 pm EST

    Hi Manish,

      yes, achieving the same behavior as in your wjFlexGridCellTemplate was exactly what we were trying to get. In the end after checking the code you provided in https://www.grapecity.com/en/forums/wijmo/angularjs--webpack-setup, I have found and resolved a problem. So we were able to achieve something similar to wjFlexGridCellTemplate.
    

    Thanks!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels