[转]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就能够对这行的数据进行操作.但实际项目里我们可 ...
随机推荐
- Java基础-super关键字与this关键字
用super调用父类构造方法 类如果没有显式声明构造方法,则自动生成无参数的默认构造方法. 1.先用一个无参数的父类构造方法验证一下, 执行子类构造方法会自动调用父类的构造方法.测试代码: class ...
- spring mvc参数绑定
spring绑定参数的过程 从客户端请求key/value数据,经过参数绑定,将key/value数据绑定到controller方法的形参上.springmvc中,接收页面提交的数据是通过方法形参来接 ...
- POJ 3449 Geometric Shapes --计算几何,线段相交
题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...
- NOIP2005过河[DP 状态压缩]
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
- [No000028]Python的使用之禅及程序员应该明白的一些道理
最近疯狂的学习ruby和python着两门语言,看到书本上一些比较赞同的段子,摘抄并翻译如下: Python的使用之禅 Beautiful is better than ugly. 美丽好过丑陋Exp ...
- uva216 Getting in Line
Computer networking requires that the computers in the network be linked. This problem considers a \ ...
- Java集合系列:-----------04fail-fast总结(通过ArrayList来说明fail-fast的原理以及解决办法)
前面,我们已经学习了ArrayList.接下来,我们以ArrayList为例,对Iterator的fail-fast机制进行了解.内容包括::1 fail-fast简介2 fail-fast示例3 f ...
- VS2013 Web项目添加引用项目后,引用上有黄色的感叹号小图标
RT,重新生成还是不行,然后重新打开VS,VS2013,还是不行. 最后,右键引用-属性-已解析 False. 为什么会未解析呢.终于找到问题根源了. 当前项目.net 4.0版,而引用的项目.net ...
- top状态及其常用技巧
看tcp状态 /bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' 在 top 状态下,按 "shif ...
- QT QDateTime类、QTimer类
QDateTime类,头文件#include <QDateTime> 可以使用QDateTime类来获得系统时间.通过QDateTime::currentDateTime()来获取本地系统 ...