T
TanStack•10mo ago
fair-rose

Using .setState(), .getState()

Can table.setState()/getState() be used with arbitrary values. I have a table cell that just shows a component which handles a calculation/formula from Query data. I need to be able to total the final results of those values for all selected rows. Ideally I'd like to just add this to row data, without precalculating it for the entire table. (Because reasons.) Instead, I'd rather the component be able to add it to the context of the row. So when I pass selected rows to the footer, it can just sum those up.
1 Reply
fair-rose
fair-roseOP•10mo ago
cell: info => {
<Pnl symbol="symbol" row={info.row} />
}
cell: info => {
<Pnl symbol="symbol" row={info.row} />
}
const Pnl = ({symbol, row}) => {
const {data: data1} = useQuery(...)
const {data: data2} = useQuery(...)

const value = ...someCalculation(data1, data2);
row._valuesCache.value = value

return <div>{value}</div>
}
const Pnl = ({symbol, row}) => {
const {data: data1} = useQuery(...)
const {data: data2} = useQuery(...)

const value = ...someCalculation(data1, data2);
row._valuesCache.value = value

return <div>{value}</div>
}
nvm, I think I should just group selected rows by symbol and sum the results of someCalculation, that should work Next step, figure out sorting. 😱

Did you find this page helpful?