zoukankan      html  css  js  c++  java
  • jqGrid 自定义格式化

    · jQuery("#grid_id").jqGrid({  

    · ...  

    ·    colModel: [   

    ·       ...   

    ·       {name:'price', index:'price', 60, align:"center", editable: true, formatter:currencyFmatter},  

    ·       ...  

    ·    ]  

    · ...  

    · });  

    ·    

    · function currencyFmatter (cellvalue, options, rowObject)  

    · {  

    ·    // do something here  

    ·    return new_format_value  

    · }

    cellvalue:要被格式化的值 
    options:对数据进行格式化时的参数设置,格式为: 
    { rowId: rid, colModel: cm} 
    rowObject:行数据

    数据的反格式化跟格式化用法相似.

    · jQuery("#grid_id").jqGrid({  

    · ...  

    ·    colModel: [   

    ·       ...   

    ·       {name:'price', index:'price', 60, align:"center", editable: true, formatter:currencyFmatter, unformat:unformatCurrency},  

    ·       ...  

    ·    ]  

    · ...  

    · });  

    ·    

    · function currencyFmatter (cellvalue, options, rowObject)  

    · {  

    ·    

    ·    return "$"+cellvalue;  

    · }  

    · function  unformatCurrency (cellvalue, options)  

    · {  

    ·    

    ·    return cellvalue.replace("$","");  

    · }  

    表格中数据实际值为123.00,但是显示的是$123.00; 我们使用getRowData ,getCell 方法取得的值是123.00。 
    创建通用的格式化函数

    · <script type="text/javascript">  

    · jQuery.extend($.fn.fmatter , {  

    ·     currencyFmatter : function(cellvalue, options, rowdata) {  

    ·     return "$"+cellvalue;  

    · }  

    · });  

    · jQuery.extend($.fn.fmatter.currencyFmatter , {  

    ·     unformat : function(cellvalue, options) {  

    ·     return cellvalue.replace("$","");  

    · }  

    · });  

    ·    

    · </script>

    具体使用:

    · jQuery("#grid_id").jqGrid({  

    · ...  

    ·    colModel: [   

    ·       ...   

    ·       {name:'price', index:'price', 60, align:"center", editable: true, formatter:currencyFmatter},  

    ·       ...  

    ·    ]  

    · ...  

    · })

  • 相关阅读:
    (转)磁盘管理(一,二)
    (转)认识 Linux 文件系统
    (转)linux磁盘分区fdisk分区和parted分区
    (转)centos7.4 fdisk磁盘分区 格式化 挂载
    (转)磁盘分区类型选择与磁盘分区配置过程
    (转)linux配置网卡的命令
    (转)磁盘阵列RAID原理、种类及性能优缺点对比
    (转)AIX 中 Paging Space 使用率过高的分析与解决
    (转)Linux内核参数设置sysctl命令详解
    (转)linux mount (挂载命令)详解
  • 原文地址:https://www.cnblogs.com/cleverJoe/p/3848840.html
Copyright © 2011-2022 走看看