zoukankan      html  css  js  c++  java
  • jquery easyui中的formatter多用法

    1.formatter能多数据进行格式化后输出,formatter必须返回一个字符串,第一个用法:当一个单元格的数据很多,不能显示完全时,鼠标放上去能动态显示出所有内容。

    formatter:function(value,rowData,rowIndex){
        //value是当前字段的值,rowData是该行的所有数据,rowIndex是该行的索引
        return '<span title="'+value+'">'+value+'</span>';
        
    }

    2.在表格中定义带按钮的一行操作列

    columns:[[
        {
            title:'控制',
            field:'id',
            150,
            formatter:function(value,rowData,rowIndex){
            //value是当前字段的值,rowData是该行的所有数据,rowIndex是该行的索引
            return '<button onclick="show('+rowIndex+');">编辑</button><button onclick="show('+rowIndex+');">删除</button>';
        
            }
            
        }
    
    ]]
    
    
    functon show(index){
        var rows= datagrid.datagrid('getRows');//得到所有的行,是一个数组
        console.info(rows[index]);//通过rows[index]就能得到该行的数据了
    }

    传数据时要传索引,因为rowData是一个对象,不能传过去。

    3.格式化日期:

    先扩展jquery的日期格式

    Data.prototype.format=function(format){
        if(isNaN(this.getMonth)){
            return '';
        }
        if(!format){
            format="yyyy-MM-dd hh:mm:ss";
        }
    
        var o={
        
            /* month*/
            "M+":this.getMonth+1,
            "d+":this.getDate(),
    
            "h+":this.getHours(),
    
            "m+":this.getMinutes(),
    
            "s+":this.getSeconds+1,
    
            "q+":Math.floor((this.getMonth()+3/3)),
            "S+":this.getMilliseconds()
        };
        if(/(y+)/.test(format)){
            format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));
        }
        for(var k in 0){
            if(new RegExp("("+k+")").test(format)){
                format=format.replace(RegExp.$1,RegExp.$1.length==1?0[k]:("00"+0[k]).substr((""+o[k]).length));
            
            }
        }
        return format;
    }

    调用方式:

    formatter:function(value){
            //value是当前字段的值
            return new Date(value).format();
        
            }
  • 相关阅读:
    2019省赛训练组队赛4.9周二 2017浙江省赛
    #Leetcode# 49. Group Anagrams
    #Leetcode# 57. Insert Interval
    POJ 2195 Going Home
    HDU 2255 奔小康赚大钱
    HDU 1083 Courses
    HDU 2063 过山车
    POJ 3041 Asteroids
    指针的妙处
    jzoj 6273. 2019.8.4【NOIP提高组A】欠钱 (money)
  • 原文地址:https://www.cnblogs.com/suncj/p/4060029.html
Copyright © 2011-2022 走看看