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,
getRowClass, I cannot use any of the component property.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
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.
Most helpful comment
Thanks a ton! So converting normal function to arrow does the magic.