【问题标题】:formatting cell values in datatables格式化数据表中的单元格值
【发布时间】:2016-10-06 00:56:55
【问题描述】:

将其用作example 如何控制单元格中值的格式?

例如,我将如何格式化 Extn. 列以读取 5,407 或 54.07?

Name    Position    Office  Extn.   Start date  Salary
Airi Satou  Accountant  Tokyo   5407    $2008/11/28 $162,700

我一直在搜索 herehere,但我无法完全解决。有人可以建议吗?

我尝试过这样的事情,但没有成功:

$(document).ready(function() {
    $('#example').DataTable( {
        data: dataSet,
        columns: [
            { title: "Name" },
            { title: "Position" },
            { title: "Office" },
            { title: "Extn." },
            { title: "Start date" },
            { title: "Salary" }
        ],
      "aoColumnDefs": [ {
                    "aTargets": [ 4 ],
                        "mRender": function (data, type, full) {
                                //var formmatedvalue=data.replace("TEST")
                            //return formmatedvalue;
                  return '$'+ data;
                            }
            }]
    } );
} );

【问题讨论】:

    标签: datatables


    【解决方案1】:

    使用columns.renderoption

    使用built-in 助手,获得一千个分隔符(5,407):

    {
      title: "Extn.",
      render: $.fn.dataTable.render.number(',', '.', 0, '')
    },
    

    JSFiddle example

    或者使用自定义函数自己做 (54.07):

    {
        title: "Extn.", render: function (data, type, row) {
            return data / 100;
        }
    
    },
    

    JSFiddle example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      相关资源
      最近更新 更多