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字段就是格式化后的数据。

  • 相关阅读:
    信息安全算法
    另类装载问题
    分治法快速排序
    动态规划最长公共子序列
    java网络编程1
    Jndi和会话bean
    EJB初探
    JSF初探
    简单计算器
    关于坐火车
  • 原文地址:https://www.cnblogs.com/ZGQ-VIP/p/10069023.html
Copyright © 2011-2022 走看看