代码改变世界

easyuidatagrid扩展--玩一下,无实际意义

2013-08-09 16:05  JerremyZhang  阅读(350)  评论(0编辑  收藏  举报

直接上代码

 1 $.extend($.fn.datagrid.defaults.editors, {
 2     operater: {
 3         init: function (container, options) {
 4             var a1 = $("<a class='easyui-linkbutton' iconCls='icon-ok' plain='true' onclick='alert()' >更新</a>").appendTo(container);//初始化编辑器并返回目标对象。
 5             a1.linkbutton(options);
 6             var a2 = $("<a class='easyui-linkbutton' iconCls='icon-cancel' plain='true' onclick='alert(this)'>取消</a>").appendTo(container);
 7             a2.linkbutton(options);
 8             return container;
 9         },
10         getValue: function (target) {
11             return $(target);
12         },
13         setValue: function (target, value) {
14             $(target).val(value);
15         },
16         resize: function (target, width) {
17             var input = $(target);
18             if ($.boxModel == true) {
19                 input.width(width - (input.outerWidth() - input.width()));
20             } else {
21                 input.width(width);
22             }
23         }
24     }
25 })


使用:
 1 $(function () {
 2             $('#tt').datagrid({
 3                 url: 'Handler.ashx',
 4                 columns: [[
 5                     { field: 'productid', title: '产品编号', width: 300, editor: "text" },
 6                     { field: 'productname', title: '产品名称', width: 300, editor: "text" },
 7                     { field: 'operation', title: '操作', width: 200, editor: "operater" }
 8                 ]],
 9                 onDblClickRow: function (rowIndex, rowData) {
10                     $("#tt").datagrid('beginEdit', rowIndex);
11                  12                 }
13             });
14 
15         })

效果: