Search code examples
angularngx-datatable

ngx-datatable cellClass as function in templateRef


I try to implement my css-classes to ngx-datatable cells like shown in the demos: https://swimlane.github.io/ngx-datatable/#css

I'm using TemplateRef (instead of inline-Templates in the demo)

  @ViewChild('Bestand_HdrTpl') Bestand_HdrTpl: TemplateRef<any>;
  @ViewChild('Bestand_Tpl') Bestand_Tpl: TemplateRef<any>;

  setColumns() {
    const dieColmn = [

      {
        cellTemplate: this.Bestand_HdrTpl,
        headerTemplate: this.Bestand_Tpl,
        prop: 'Bestand',
        name: 'LAGER_Bestand',
        canAutoResize: false,
        width: 65,
        cellClass: 'ist-bestand'
      },
      ...
      ,
      {
        cellTemplate: this.Lager_Tpl,
        headerTemplate: this.Lager_HdrTpl,
        prop: 'Lager',
        name: 'ID'
      }
    ];

    return dieColmn;
      

How do I implement the cellClass-property to call my function?

getCellClass({ row, column, value }): any {

    return {

      // css-class    true oder false
      'ist-bestand': value > 0
    };

  }

I tried:

      {
        ...

        width: 65,
        cellClass: 'getCellClass'
      },

    

      {
        ...

        width: 65,
        cellClass: "'getCellClass"'
      },

    

Is it even possible with TemplateRef?


Solution

  • I think there is no way to add css-classes to a TemplateRef.

    For practical reasons I changed all to Online-Templates.