Greetings
Intro
- Full stack node/react developer that just started using patternfly for a new project and LOVE IT!
Issue
-
The react table documentation says that you can pass arrays of objects to tables.
-
This is how all data comes out from api calls, not hard to convert but is annoying (especially when the rest of your state relies on arrays of objects)
-
To get around it I have implemented this in my classes:
// conversion function for pattern fly table data requirements, this will be used a lot
convertObjArray = (data) => {
let dataArray = [];
let containerArray = [];for(let i=0; i<data.length; i++){ dataArray = []; console.log(data[i]); data[i].edit = <div> <Button key={"e_" + data[i].StoreId} variant="primary" onClick={this.patchStore} className="edit" >Edit</Button> <Button key={"c_" + data[i].StoreId} variant="danger" onClick={this.confirm} className="confirm" >Confirm</Button> </div>; const obj = data[i]; for(let prop in obj){ dataArray.push(obj[prop]); } containerArray.push(dataArray); } this.setState({ rows: containerArray, });
}
I really hope that I am just out to lunch on this one and there is just something I am doing wrong.
Thanks!