Description
- Sometimes the data that comes back from the server has no suitable key. KeyField auto increment #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). Implement Multiple columns as keys #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:boolean
to the column definitions. The table would then call the existingcolumn.formatter
function (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 Two columns have same dataField will cause the same key warning of React #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.