zoukankan      html  css  js  c++  java
  • EasyUI datagrid formatter 属性

    easyui的formatter属性可以帮助我们更加灵活的显示数据库中的数据。

    比如,我有一个启用禁用字段,使用数字表示,1表示启用,2表示禁用,展示给客户的时候我当然希望是中文的形式。

    只需要写这么一个formatter方法:(isu就是这个字段)


    function formatterIsu(value, row, index){
    if(row.isu==1){
    return "启用";
    }else if(row.isu==2){
    return "禁用";
    }
    }

    然后在<th>标签里的将这个函数赋值给formatter属性:


    最后页面上输出的就是中文的启用,禁用了。

    很多时候,创建表格头也是通过js来完成,里面也是可以加入formatter函数来格式化字段的:


    $(document).ready(function() {
    $('#dg').datagrid({
    url : "/bboo/resource/gj-resource!queryResource.do",
    columns : [ [ {
    field : 'resourceId',
    title : '菜单id',
    width : 50,
    sortable : true
    }, {
    field : 'description',
    title : '描述',
    width : 50,
    sortable : true
    }, {
    field : 'name',
    title : '名称',
    width : 50,
    sortable : true
    }, {
    field : 'sort',
    title : '分类',
    width : 50,
    sortable : true
    }, {
    field : 'type',
    title : '类型',
    width : 50,
    sortable : true
    }, {
    field : 'value',
    title : 'url值',
    width : 50,
    sortable : true
    }, {
    field : 'pid',
    title : '父菜单',
    width : 80,
    formatter : function(value, row, index) {
    if (row.parent) {
    return row.parent.resourceId;
    } else {
    return value;
    }
    }
    } ] ]
    });
    });

    上面的pid字段就是格式化后的数据。

  • 相关阅读:
    Akka框架使用注意点
    log4j配置文件加载
    iptables常规使用
    linux ipv6临时地址
    组合数取模Lucas定理及快速幂取模
    Shell变量的定义与赋值操作注意事项
    虚拟机软件bochs编译使用问题
    实现一个简陋操作系统的相关笔记日志
    linux内核增加系统调用--Beginner's guide
    c语言几种异常
  • 原文地址:https://www.cnblogs.com/ZGQ-VIP/p/10069023.html
Copyright © 2011-2022 走看看