0

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?

MarBl
  • 1
  • 4
  • I changed all to Online-Templates... – MarBl Jan 16 '19 at 04:37
  • You can do it like this: `{ cellTemplate: this.Bestand_HdrTpl, headerTemplate: this.Bestand_Tpl, prop: 'Bestand', name: 'LAGER_Bestand', canAutoResize: false, width: 65, cellClass: this.getCellClass } ` ` getCellClass({ row, column, value }): any { return value > 0 ? " ist-bestand" : '' ; }` – Sushmit Sagar Apr 12 '19 at 10:42

1 Answers1

0

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

For practical reasons I changed all to Online-Templates.

MarBl
  • 1
  • 4