简体   繁体   中英

ag-grid: format number - Need to display 0.123 as .123 in grid

New to ag-grid; I've made a few futile attempts using numberParser, cellRendering, etc. I've gotten my JSON to ltrim the leading 0, but the grid reapplies on display.

Need 0.123 to display as .123

Help!

The cell renderer seems to be right option here. In solution presented below, the float is converted to string and trimmed giving .xxx result - from that moment ag-grid cell value is a string and not a number anymore, so please apply correct filtering/settings if needed:

cellRenderer: function(params) {
    //Transform float value to string and trim leading 0
    return params.value.toString().replace(/^0+/, "");
}

Working example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM