简体   繁体   English

ag-grid:格式编号 - 需要在网格中将 0.123 显示为 .123

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

New to ag-grid; 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.我已经使用 numberParser、cellRendering 等做了一些徒劳的尝试。我已经让我的 JSON 来 ltrim 前导 0,但网格重新应用在显示上。

Need 0.123 to display as .123需要 0.123 才能显示为 0.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:在下面介绍的解决方案中,浮点数被转换为字符串并修剪给出.xxx结果 - 从那一刻起,ag-grid 单元格值是一个字符串而不是一个数字,所以如果需要,请应用正确的过滤/设置:

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

Working example 工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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