[转]jQuery EasyUI自定义DataGrid的Editor
原文地址:http://www.jeasyuicn.com/post-3.html
官网datagrid的api:http://jquery-easyui.wikidot.com/document:datagrid
首先,先看看官方的editor的介绍:

可以看到如果我们要自定义一个editor,需要实现四个方法(init,getValue,setValue,resize)。
下面是我自己扩展的一个datetimebox类型
01 |
$.extend($.fn.datagrid.defaults.editors, { |
02 |
datetimebox: {//datetimebox就是你要自定义editor的名称 |
03 |
init: function(container, options){ |
04 |
var input = $('<input class="easyuidatetimebox">').appendTo(container); |
05 |
return input.datetimebox({ |
06 |
formatter:function(date){ |
07 |
return new Date(date).format("yyyy-MM-dd hh:mm:ss"); |
08 |
} |
09 |
}); |
10 |
}, |
11 |
getValue: function(target){ |
12 |
return $(target).parent().find('input.combo-value').val(); |
13 |
}, |
14 |
setValue: function(target, value){ |
15 |
$(target).datetimebox("setValue",value); |
16 |
}, |
17 |
resize: function(target, width){ |
18 |
var input = $(target); |
19 |
if ($.boxModel == true){ |
20 |
input.width(width - (input.outerWidth() - input.width())); |
21 |
} else { |
22 |
input.width(width); |
23 |
} |
24 |
} |
25 |
} |
26 |
}); |
这是最终出来的效果:


使用方法:
<th field="datetime" width="150" editor="datetimebox">datetime</th>
或者:
在配置里面
{
field:"dataTime",
editor:"datetimebox"
}
一般我们只许要注意init,getValue和setValue这三个方法,最主要的还是init的方法的实现。需要注意的是,这里的set和getValue方法都是针对于editor的,是给editor设值和获取值的。
上面例子中涉及到的format方法:
//时间格式化
Date.prototype.format = function(format){
/*
* eg:format="yyyy-MM-dd hh:mm:ss";
*/
if(!format){
format = "yyyy-MM-dd hh:mm:ss";
} var o = {
"M+": this.getMonth() + 1, // month
"d+": this.getDate(), // day
"h+": this.getHours(), // hour
"m+": this.getMinutes(), // minute
"s+": this.getSeconds(), // second
"q+": Math.floor((this.getMonth() + 3) / 3), // quarter
"S": this.getMilliseconds()
// millisecond
}; if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
} for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" +o[k]).length));
}
}
return format;
};
[转]jQuery EasyUI自定义DataGrid的Editor的更多相关文章
- 第二百二十二节,jQuery EasyUI,DataGrid(数据表格)组件
jQuery EasyUI,DataGrid(数据表格)组件 学习要点: 1.加载方式 2.分页功能 本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于 Pa ...
- 给Jquery easyui 的datagrid 每行增加操作链接(转)
http://www.thinkphp.cn/code/207.html 通过formatter方法给Jquery easyui 的datagrid 每行增加操作链接我们都知道Jquery的EasyU ...
- JQuery EasyUI的datagrid的使用方式总结
JQuery EasyUI的datagrid的使用方式总结第一步:添加样式和js脚本在前台添加展示数据表格的table元素 例如: <div> <table id="tt& ...
- JQuery EasyUI中datagrid的使用
在学习过程中,可以参照JQuery EasyUI的官方网站学习.地址:http://www.jeasyui.com/demo/main/index.php 在学习JQuery EasyUI中的Data ...
- JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)
需求如下 现有数据列三列 Name,Age,CreateDate 数据 张三,18,2000-12-09 :12:34:56 李四,28,2000-12-09 :12:34:56 王麻子,38,200 ...
- jQuery EasyUI之DataGrid使用示例
jQuery EasyUI是一个轻量级的Web前端开发框架,提供了很多的现成组件帮助程序员减轻前端代码开发量,之前有个项目中就用到了其中的DataGrid. jQuery EasyUI框架的官方主页: ...
- jquery easyui的datagrid在初始化的时候会请求两次URL?
我们项目前端用的是jquery easyui,刚开始使用datagrid加载列表初始化时总是请求两次URL,这让人非常不解,怎么总是请求两次呢?数据一多,加载速度明显变慢,通过查资料才知道原来是重复声 ...
- Easyui的datagrid的editor(行编辑器)如何扩展datetimebox类型
在easyui的datagrid扩展方法中添加这样的时间日期(datetimebox)代码块 放在 $.extend($.fn.datagrid.defaults.editors,{datetim ...
- 给Jquery easyui 的datagrid 每行添加操作链接
背景 我们都知道Jquery的Easy-UI的datagrid能够加入而且自己定义Toolbar,这样我们选择一行然后选择toolbar的对应button就能够对这行的数据进行操作.但实际项目里我们可 ...
随机推荐
- NYOJ-取石子(六)
取石子(六) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 最近TopCoder的PIAOYI和HRDV很无聊,于是就想了一个游戏,游戏是这样的:有n堆石子,两个人轮流 ...
- USACO3.1Humble Numbers[...]
题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包括,p1.p1*p2.p1*p1.p1*p2*p3. ...
- C#添加测量运行时间
使用范围 使用模块化开发,每个模块都有初始化功能,初始化功能可能包括:加载配置表,初始化事件,初始化设置 那么如果想测量每个模块的Init时间呢?Net框架已经提供了测量运行的方法 System.Di ...
- NGUI Label Color Code
UILabel的颜色代码 NGUI的Label文档:http://www.tasharen.com/?page_id=166 you can embed colors in [RrGgBb] form ...
- Maven学习(七)仓库
* Maven仓库 在项目开发中, 项目目录下往往会有一个lib目录,用来存放第三方依赖jar文件, 如spring log4j jar等文件, Maven仓库就是放置JAR文件(WAR,ZIP,P ...
- Flex布局教程及属性速查
一.Flex布局介绍 伸缩盒模型(flexbox)是一个新的盒子模型,意为"弹性布局",用来为盒状模型提供最大的灵活性,主要优化了UI布局.Flexbox的功能主要包手:简单使用一 ...
- uva146 ID codes
Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...
- linux下打开txt显示乱码的解决方法
Linux打开txt文件乱码的解决方法 Linux显示在Windows编辑过的中文就会显示乱码是由于两个操作系统使用的编码不同所致.Linux下使用的编码是utf8,而Windows使用的是gb1 ...
- Hoj2634 How to earn more?
How to earn more My Tags (Edit) Source : ww Time limit : 1 sec Memory limit : 64 M Submitted ...
- JavaScript数组定义
数组有四种定义的方式 使用构造函数: var a = new Array(); var b = new Array(8); var c = new Array("first", & ...