码迷,mamicode.com
首页 > Web开发 > 详细

jquery easyui中的formatter多用法

时间:2014-10-29 19:06:26      阅读:459      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   for   sp   数据   div   

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

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

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

columns:[[
    {
        title:‘控制‘,
        field:‘id‘,
        width: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();
    
        }

 

jquery easyui中的formatter多用法

标签:style   blog   io   color   ar   for   sp   数据   div   

原文地址:http://www.cnblogs.com/suncj/p/4060029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!