Access types of the cell value
First time really taking a look at tanstack table. I'm trying to get off of muix-data-table potentially to use some of the (should be free features) like row pinning etc.
Currently have a semi working table in my react app working with data the looks like this
Within the cells in a specific column I am trying to format the data in a particular way, like in this example:
I'm getting an error on the
const change
that Type 'string' is not assignable to type 'number'.
. From what could gather I thought the purpose of the createColumnHelper()
was supposed to help with this in some sort. But is everything as far as cells are concerned just strings? Might be missing a function somewhere since the documentation is pretty large and I'm just getting started, or if there is a better way to do this? I also obviously tried just using the value from getValue()
but that was unknown. Is there a way so the accessor methods just know the type of each cell based off of the ColumnDef
s?1 Reply
eastern-cyanOP•2y ago
So I see that
accessorFn
on ColumnDef
says "The accessor function to use when extracting the value for the column from each row." and that getValue
from the Cell
says "Returns the value for the cell, accessed via the associated column's accessor key or accessor function.", but I cannot seem to get them to play along. If I do this just for a sanity check
the console.log()
at the end has access to the type of percentageChange
thus letting me do toFixed()
on it. I guess I'm just missing something.