Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right way to forceUpdate on Cell? #596

Closed
dkwin opened this issue Jan 6, 2017 · 4 comments
Closed

Right way to forceUpdate on Cell? #596

dkwin opened this issue Jan 6, 2017 · 4 comments
Labels

Comments

@dkwin
Copy link

dkwin commented Jan 6, 2017

Hi guys

I was curious as to the right way to forceUpdate on a Cell?

The way I've found out so far is to add a callback to ReactDataGrid.Row's cellRenderer

IE

<ReactDataGrid
    rowFormatter={CustomRowFormatter}
    ...
/>


  CustomRowFormatter extends React.Component {

 handleCellRenderer (publicProps, publicContext, queue) {
       return <ReactDataGrid.Cell {...publicProps} forceUpdate={true}/>
 }

  render (){
         return <ReactDataGrid.Row {...this.props} forceUpdate={true} cellRenderer=         {this.handleCellRender.bind(this)}/>;
  }

}

However, I keep seeing errors in regards to refs to the Cells

warning.js:36 Warning: Stateless function components cannot be given refs (See ref "foo" in bound handleCellRender created by Row). Attempts to access this ref will fail.

Is there a better way to forceUpdate on a cell?

@malonecj
Copy link
Contributor

malonecj commented Jan 6, 2017

Best way is to create a custom cell renderer class, which you then pass as prop in your custom row renderer

class CustomCellRenderer extends  React.Component {
   render() {
     return <ReactDataGrid.Cell {...publicProps} forceUpdate={true}/>
   }

CustomRowFormatter extends React.Component {

  render (){
         return <ReactDataGrid.Row {...this.props} forceUpdate={true} cellRenderer=         {CustomCellRenderer}/>;
  }

@dkwin
Copy link
Author

dkwin commented Jan 7, 2017

@malonecj

Thanks for the info,

one other question,

Is there a way to pass an object/property/whatever from ReactDataGrid to Row or Cell?

For example

    <ReactDataGrid
         propertyToPassToCellAndRow={someProperty}
    />
CustomRowFormatter extends React.Component {

  render (){
         let usefulPropertyFromGrid =  this.props.propertyToPassToCellAndRow;

         //do something with usefulPropertyFromGrid 
         return <ReactDataGrid.Row {...this.props} />;
  }

I guess I can modify the rows object and insert something into each row object but it seems like it would be fairly hacky to do so.

@dkwin
Copy link
Author

dkwin commented Jan 9, 2017

Also,

class CustomCellRenderer extends  React.Component {
   render() {
     return <ReactDataGrid.Cell {...publicProps} forceUpdate={true}/>
   }

needs to have setScrollLeft defined if using the freezing columns functionality, I get an error thrown that setScrollLeft is not defined when trying to define my own CellRenderer in the Row object.

@diogofcunha
Copy link
Contributor

Let's keep this kind of questions to Stack Overflow like it is requested in here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants