Ngx-datatable: Need a feature to access extra parameters (other than just `row`) inside `getRowClass` function

Created on 23 Jan 2018  路  3Comments  路  Source: swimlane/ngx-datatable








I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior
As of now, getRowClass function has just one argument: row .
And only the predefined the CSS class we can provide to format the row.
My requirement is,

  1. the formatting options/criteria I receive from the server.
  2. based on the formatting options, I create CSS classes dynamically in JavaScript.
  3. I keep these CSS class names and criterias as an array as the component property
  4. ingetRowClass, I cannot use any of the component property.
  5. even if I try to get other things using this keyword, it gives me scope of DataTableBodyRowComponent.

Expected behavior

I have provided the technical expectations as comments in this Plunk

Reproduction of the problem this is a feature request

What is the motivation / use case for changing the behavior?

To get access to the component's other properties inside getRowClass method.

Please tell us about your environment:

  • Table version: 1.0.3

  • Angular version: 4.3.3

  • Browser: all

  • Language: TypeScript 2.3.3

Most helpful comment

Thanks a ton! So converting normal function to arrow does the magic.

<ngx-datatable class='material striped'
        [rows]='rows'
        [rowClass]='getRowClassArrowSimple'
     ...>
</ngx-datatable>
  /**
   * This method's 'this' referes to the app component
   */
  getRowClassArrowSimple = (row) => {
    console.log(this.applyStyles); // => this.applyStyles is a component's property
    return {
      'myClass': this.applyStyles
    }
  }

All 3 comments

I've just run into the same problem, and solved it by making the function that you pass into the datatable in the rowClass input an arrow function. Now _this_ refers to the component instance.

I've created an example here: https://stackblitz.com/edit/angular-hpwj7a?file=app%2Fapp.component.ts

Thanks a ton! So converting normal function to arrow does the magic.

<ngx-datatable class='material striped'
        [rows]='rows'
        [rowClass]='getRowClassArrowSimple'
     ...>
</ngx-datatable>
  /**
   * This method's 'this' referes to the app component
   */
  getRowClassArrowSimple = (row) => {
    console.log(this.applyStyles); // => this.applyStyles is a component's property
    return {
      'myClass': this.applyStyles
    }
  }

i have done the same class is added to the row but it is still not working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JanStock picture JanStock  路  3Comments

mmrath picture mmrath  路  3Comments

eddy-geek picture eddy-geek  路  3Comments

ChanBen picture ChanBen  路  3Comments

devendraYebhi picture devendraYebhi  路  3Comments