1

So I have a react bootstrap table (very simplified version):

<BootstrapTable data={gameData}>
  <TableHeaderColumn dataField="player">
    Player username
  </TableHeaderColumn>
  <TableHeaderColumn dataField="games">
    Game1 score
  </TableHeaderColumn>
  <TableHeaderColumn datafield="games">
    Game2 score
  </TableHeaderColumn>
  <TableHeaderColumn datafield="total">
    Total score
  </TableHeaderColumn>
</BootstrapTable>   

And I have data coming from somewhere like this:

{
"player" : "playerName",
"games": {
    "game1": "10",
    "game2": "15",
}
"total" : "25"
}

I want to be able to sort the table, and to do so each tableheader needs to have it's own datafield. I am able to sort player, and total score since they have their own datafield, but I am not able to sort games score. I tried this:

 datafield="games.game1">
 datafield="games.game2">

But it does not work. I am really new to react, so is there any way I can solve this problem?

Thanks for the help

1
  • have you tried it by adding dataFormat={showGame1} after the datafield attribute, and then adding following function 'function showGame1(cell, row) { return cell.game1; }' With this you should be able to get nested fields Commented Jul 4, 2018 at 9:47

1 Answer 1

1

react-bootstrap-table doesn't support the nested data field. but react-bootstrap-table-next it does. you can check this demo and also this.

I think you can consider to use react-bootstrap-table-next. here is the official website :)

Sign up to request clarification or add additional context in comments.

2 Comments

I have already solved this problem by creating a javascript function that flattens the object, so that there are no nested objects/children, but then sorting is the next problem I have.
@JohnDoeveto about the sorting problem I think the only way to fix is custom a sort function by yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.