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},  

    ·       ...  

    ·    ]  

    · ...  

    · })

  • 相关阅读:
    Vue组件开发实例(详细注释)
    Vue组件进阶知识总结
    webpack配置:打包第三方类库、第三方类库抽离、watch自动打包、集中拷贝静态资源
    webpack配置:less/sass文件打包和分离、自动处理css前缀、消除未使用的css及完整的webpack.config.js文件
    webpack配置:增加babel支持、打包后调试
    webpack配置:图片处理、css分离和路径问题
    webpack配置:css文件打包、JS压缩打包和HTML文件发布
    使用webpack构建本地服务器
    Webpack安装和配置
    npm模块安装机制
  • 原文地址:https://www.cnblogs.com/cleverJoe/p/3848840.html
Copyright © 2011-2022 走看看