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

    ·       ...  

    ·    ]  

    · ...  

    · })

  • 相关阅读:
    java多线程的基本介绍
    Fragment基本介绍
    TypedValue.applyDimension的使用
    获取当前进程名并判断是否是主进程
    Bitmap类、BitmapFactory及BitmapFactory类中的常用方法
    Android 动态改变图片的颜色值
    Glide4.0使用
    Android在一个app中启动另一个App
    使用Recyclerview实现图片水平自动循环滚动
    Java变量的修饰符
  • 原文地址:https://www.cnblogs.com/cleverJoe/p/3848840.html
Copyright © 2020-2023  润新知