基于数据值的AG网格小数精度 [英] AG-grid Decimal Precision based on the values of the data

查看:96
本文介绍了基于数据值的AG网格小数精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格中有一些十进制值列,我希望基于十进制值具有可变精度。具体而言,如果值> 9.5,则精度的小数位应为0,如果该值在0.5至9.5之间,则精度应为1。否则为2。
当前,我在像这样的列定义中定义精度:

I have some decimal value columns in a grid where I want to have a variable precision based on the values of the decimal. Specifically, decimal places of precision should be 0 if the value is > 9.5, precision should be 1 if the number is between 0.5 and 9.5 & 2 otherwise. Currently, I am defining the precision in the column definitions like this:

"columns": [
    {
        "name": "exposure",
        "type": "DECIMAL",
        "title": "Exposure",
        "precision": 2,
        "width": 77
    },
    {
        "name": "total_risk",
        "type": "DECIMAL",
        "title": "Total Risk",
        "agg_name": "Total Risk",
        "precision": 0,
        "width": 78
    }]

网格是否提供任何此类功能。我没有在官方文档中看到任何内容

Does ag grid provide any functionality like this. I don't see anything in the official documentation

推荐答案

您可以通过 valueFormatter处理显示值 columnDef

columnDefs = [
  {
    headerName: "Sample data",
    field: "sampleNumber",
    valueFormatter: numberFormatter,
    width: 200
  }
];
...
numberFormatter(params){
    // params.data - full row data
    // params.value - cell value
    // here you can handle how certain cell data would be displayed on the grid
    return Number(params.value.toFixed(params.data.samplePrecision))
}

这是一个正常工作的 plnkr示例

官方文档表示值设置器& 值解析器

这篇关于基于数据值的AG网格小数精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆