Description (Package: Core/Table):
There should be an override point to alter cell data before passing it to Cell component. like for example we can have a method cellValue
in TableColumnConfig, or we can somehow use existing formatter
method for this purpose. This will unlock many possibilities i.e. CustomComponent can also receive custom modified data without polluting existing data array.
Example:
Currently we have:
<Cell
rowId={id}
key={fieldName}
rowData={rowData}
data={rowData[config.field]}
...
/>
The new proposal is to pass modified value:
// method format
cellValue: (cellData, rowData) => {
return 'something'
}
.....
<Cell
rowId={id}
key={fieldName}
rowData={rowData}
data={cellValue(rowData[config.field], rowData)}
...
/>
Real world usecase:
Suppose we have order data:
[
{
orderNumber: 'some number',
amount: 'some number',
placedOn: 'some date',
deliveredOn: 'some date',
receivedOn: 'some date',
},
...
]
Now we need to construct table with three field => orderNumber, amount, status. We need to calculate status by looking at fields => placedOn, deliveredOn, receivedOn. By using cellValue
method we can achieve this easily without polluting original data array, and even if we are using CustomComponent then it can be used there also.
One argument here may be like we are anyway passing rowData to CustomComponent, then why we need this extra cellValue?, we still need this because in that CustomComponent we have to depend upon strings like 'placedOn' etc to extract data from rowData, which will harm CustomComponent's reusability.