Datatable edit example problem

UI Components for React
Post Reply
rossd
Posts: 18
Joined: 26 Oct 2015, 06:51

23 Feb 2018, 03:14

Greetings!

I was working on a datatable with editing of one of the columns, and have some problems with the demo example code.

Firstly, it has some bad paths in the import statements - not a huge problem, but suggests that the example code is different to the running example.

Secondly, the example shows two different ways to pass member functions down into the datatable:

type 1:
saleDateEditor(props) {
return (
<Calendar value={this.state.cars[props.rowIndex].saleDate}
onChange={(e) => this.onEditorValueChange(props, e.value)} style={{width:'100%'}} />
);
}

and type 2:
<Column field="saleDate" header="Sale Date" editor={this.saleDateEditor}

If I use the type 2, when I debug the saleDateEditor function, it says that "this" is a class, but not the class I am working on, just class - and as a result this.state.XXX is not found. When I changed my code to be like type 1, eg:
<Column field="Description" header="Question text" editor={(p) =>this.descEditor(p)}/>

it works fine!

I am a React newby so I don't want to describe what the difference is, but the examples should be fixed please.

Thanks

Ross
(couple years PrimeFaces user)

billb
Posts: 4
Joined: 22 Feb 2018, 21:58

23 Feb 2018, 20:18

Ross,
You should be able to make that a fat arrow function and this would become valid.

Code: Select all

saleDateEditor = (props) => { 
return (
<Calendar value={this.state.cars[props.rowIndex].saleDate}
onChange={(e) => this.onEditorValueChange(props, e.value)} style={{width:'100%'}} />
);
}
But ya, probably good for a doc update. I too encountered the bad import statements. I don't suppose this is open sourced to where we could fork and make the fixes ourselves.

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests