question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[cellClass]/[rowClass] function does not have the scope of component class

See original GitHub issue

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 at the moment it is not possible, to add a style-classe depending on a property from the component (in the plnkr example below you can see one property name I’m checking against in the getClass-fucntion and one hardcoded - which does work).

is there already a way to inject some properties into the function over the template? or is it possible to change the function call internally to apply the scope from the class?

Expected behavior possibility to change the scope of the function to the scope of the component where the function belongs to, or the possiblity to inject parameters for some checks

Reproduction of the problem

http://plnkr.co/edit/iQWBqGpJwt0o9sB0BzOk

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

my special need for it is to highlight rows when they match on a property which is set in the component class

Please tell us about your environment:

  • Table version: 9.1.0
  • Angular version: 4.1.1
  • Browser: [all]
  • Language: [all]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
eppsiloncommented, May 26, 2017

Possible workaround:

Instead of this:

@Component({
  ...,
  template: `<ngx-datatable [rowClass]="getRowClass"></ngx-datatable>`
})
class SomeComponent {
  otherFunc() {
    return true;
  }

  getRowClass(row) {
    return {
      'some-class': this.otherFunc()
    };
  }
}

Do this:

@Component({
  ...,
  template: `<ngx-datatable [rowClass]="rowClass"></ngx-datatable>`
})
class SomeComponent {
  otherFunc() {
    return true;
  }

  rowClass = (row) => {
    return {
      'some-class': this.otherFunc()
    };
  }
}
3reactions
GFoley83commented, Feb 18, 2018

You can also use an anonymous arrow func to reference the component scope:

@Component({
  ...,
  template: `<ngx-datatable [rowClass]="rowClass"></ngx-datatable>`
})
class SomeComponent {
  someVariable = true;

  rowClass = (row) => {
    return {
      'some-class': (() => { return this.someVariable === row.someVariable })()
    };
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

spring - @Scope("prototype") bean scope not creating new bean
I want to use a annotated prototype bean in my controller. But spring is creating a singleton bean instead. Here ...
Read more >
Spring @Component Annotation - Baeldung
@Component is an annotation that allows Spring to automatically detect our custom beans. In other words, without having to write any explicit ...
Read more >
4.4 Bean scopes - Spring
The non-singleton, prototype scope of bean deployment results in the creation of a new bean instance every time a request for that specific...
Read more >
Spring Bean Scopes | DigitalOcean
Let's define the spring configuration class where we will define the method to get MyBean instance from spring container. package com.journaldev ...
Read more >
Define spring component in spesific scope
How to define a spring bean as jira spring component module in atlassian-plugins.xml file For example, how can i convert this spring bean...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found