KeyField enhancement suggestion
See original GitHub issue- Sometimes the data that comes back from the server has no suitable key. https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/166 (Like data from several different sources in one result, etc). the table requires a keyField. So, what happens is I create an extra field in my object, do a map operation on it to set the keyFields to a simple rowIndex number:
data.map((val, ix) => {
val.id = ix
return val
}),
- Sometimes the data that comes back from the server has a key that is calculated from several other columns (composite key). https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/113 Again, this can be solved in the same was as the above - but instead of using the rowIndex, you calculate the key:
data.map((val, ix) => {
val.id = val.field1+value.field2
return val
}),
I would like to propose a better solution to the above.
- Add a
isKeyField:booleanto the column definitions. The table would then call the existingcolumn.formatterfunction (if provided or use ``dataField)to calculate the key. With that code the developer could easily build a composite key or use something like https://www.npmjs.com/package/shortid https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/601
The other part of this solution is the automatic numbering. Since the formatter function receives a rowIndex as a parameter, it could simply return this number.
Currently the table requires keyField property to be populated. The above implementation would imply that it would require keyField or a column isKeyField=true. However, I think it would would be a good feature of the table that if there is no keyField set on the table…and no isKeyField column, that the rowIndex would be used as a default implementation.
I think this solves all the referenced tickets and seems like it would be a fairly easy implementation? If this isKeyField existed, I would personally always use that instead of the keyField property…possibly you could consider deprecating the keyField property on the table in favor of the much more flexible column definition.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:14 (4 by maintainers)

Top Related StackOverflow Question
@AllenFang Any updates on this? I’m really interested in this update, could you tell me when you’ll implement this feature? Or you can suggest me how to use the bootstrap table with a composite key?
@AllenFang Any update on this one?