I am displaying numbers in my cells and for the colDefs, I only want to show them to 2dp. So within my colDefs I have this –
valueFormatter: (params: ValueFormatterParams) => params.value?.price?.toFixed(2)
I would like to add the ability for the user to double click on the cell and for it to show the full number (but when they click away it goes back to the 2dp format).
I have attached onCellDoubleClicked to my grid however I am having trouble sorting this.
<Grid
onGridReady={onGridReady}
{...gridOptions}
quickFilterText={searchValue}
onCellDoubleClicked={manageCellDoubleClick}
/>
I know there is setDataValue available in the click event as I tried to use this however I don’t want to change the data (because I still want the full number to be always there on copy/paste/export etc.). I just want the full number to be revealed and then for it to go back to the 2dp format when you click away.
Is there a way to do this?
2
Answers
We can use
onCellDoubleClicked
event to trigger a toggle on variableisFull
on the row data.On the formatter, using a ternary condition we can toggle the full/rounded value as shown below!
Then finally, we can add a
onCellClicked
listener to reset theisFull
property to false, to bring it back to the old state, it only works when you click another cell in the grid!full code
plunkr
possible disadvantage of this is that you then mutate rowData with view logic which IMHO is not ideal.