datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力。

看一个例子效果图:

代码如下:

  1. $('#tt').datagrid({
  2. title:'Editable DataGrid',
  3. iconCls:'icon-edit',
  4. width:660,
  5. height:250,
  6. singleSelect:true,
  7. idField:'itemid',
  8. url:'datagrid_data.json',
  9. columns:[[
  10. {field:'itemid',title:'Item ID',width:60},
  11. {field:'productid',title:'Product',width:100,
  12. formatter:function(value){
  13. for(var i=0; i<products.length; i++){
  14. if (products[i].productid == value) return products[i].name;
  15. }
  16. return value;
  17. },
  18. editor:{
  19. type:'combobox',
  20. options:{
  21. valueField:'productid',
  22. textField:'name',
  23. data:products,
  24. required:true
  25. }
  26. }
  27. },
  28. {field:'listprice',title:'List Price',width:80,align:'right',editor:{type:'numberbox',options:{precision:1}}},
  29. {field:'unitcost',title:'Unit Cost',width:80,align:'right',editor:'numberbox'},
  30. {field:'attr1',title:'Attribute',width:150,editor:'text'},
  31. {field:'status',title:'Status',width:50,align:'center',
  32. editor:{
  33. type:'checkbox',
  34. options:{
  35. on: 'P',
  36. off: ''
  37. }
  38. }
  39. },
  40. {field:'action',title:'Action',width:70,align:'center',
  41. formatter:function(value,row,index){
  42. if (row.editing){
  43. var s = '<a href="#" onclick="saverow('+index+')">Save</a> ';
  44. var c = '<a href="#" onclick="cancelrow('+index+')">Cancel</a>';
  45. return s+c;
  46. } else {
  47. var e = '<a href="#" onclick="editrow('+index+')">Edit</a> ';
  48. var d = '<a href="#" onclick="deleterow('+index+')">Delete</a>';
  49. return e+d;
  50. }
  51. }
  52. }
  53. ]],
  54. onBeforeEdit:function(index,row){
  55. row.editing = true;
  56. $('#tt').datagrid('refreshRow', index);
  57. },
  58. onAfterEdit:function(index,row){
  59. row.editing = false;
  60. $('#tt').datagrid('refreshRow', index);
  61. },
  62. onCancelEdit:function(index,row){
  63. row.editing = false;
  64. $('#tt').datagrid('refreshRow', index);
  65. }
  66. });

原文及下载地址:http://jquery-easyui.wikidot.com/tutorial:datagrid12

jquery-easyui中表格的行编辑功能的更多相关文章

  1. jquery-easyui 中表格的行编辑功能

    具体实现代码如下: <table id="tt"></table> $('#tt').datagrid({ title:'Editable DataGrid ...

  2. EasyUI中datagrid的行编辑模式中,找到特定的Editor,并为其添加事件

    有时候在行编辑的时候,一个编辑框的值要根据其它编辑框的值进行变化,那么可以通过在开启编辑时,找到特定的Editor,为其添加事件 // 绑定事件, index为当前编辑行 var editors = ...

  3. JQuery Easyui/TopJUI表格基本的删除功能(删除当前行和多选删除)

    需求:数据表格datagrid实现删除当前行和多选删除的功能. html <a href="javascript:void(0)" data-toggle="top ...

  4. (原创)EasyUI中datagrid的行编辑模式中,找到特定的Editor,并为其添加事件

    有时候在行编辑的时候,一个编辑框的值要根据其它编辑框的值进行变化,那么可以通过在开启编辑时,找到特定的Editor,为其添加事件 // 绑定事件, index为当前编辑行 var editors = ...

  5. 雷林鹏分享:jQuery EasyUI 数据网格 - 启用行内编辑

    jQuery EasyUI 数据网格 - 启用行内编辑 可编辑的功能是最近添加到数据网格(datagrid)的.它可以使用户添加一个新行到数据网格(datagrid).用户也可以更新一个或多个行. 本 ...

  6. 给Jquery easyui 的datagrid 每行增加操作链接(转)

    http://www.thinkphp.cn/code/207.html 通过formatter方法给Jquery easyui 的datagrid 每行增加操作链接我们都知道Jquery的EasyU ...

  7. Jquery EasyUI中treegrid

    Jquery EasyUI中treegrid的中右键菜单和一般按钮同时绑定事件时的怪异事件 InChatter系统开源聊天模块前奏曲   最近在研究WCF,又因为工作中的项目需要,要为现有的系统增加一 ...

  8. jquery easyUI中combobox的使用总结

    jquery easyUI中combobox的使用总结 一.如何让jquery-easyui的combobox像select那样不可编辑?为combobox添加editable属性 设置为false ...

  9. 求助关于jquery easyUI中的treegrid组件,请各位帮忙给个思路,谢谢啦

    现在项目中用到jquery easyUI中的treegrid组件,已经可以正常显示了.但是在保存的时候遇到问题,页面上参照官网的例子可以在页面更新,但是怎么获取编辑后的数据进而保存到数据库呢?

随机推荐

  1. android application plugins framework

    android插件式开发 android application plugins framework http://code.google.com/p/android-application-plug ...

  2. C++面向过程解决三阶行列式问题

    #include<iostream> #include <cstdlib> using namespace std; int print() { cout<<&qu ...

  3. Ubuntu下Eclipse中文乱码问题解决(转)

    Ubuntu下Eclipse中文乱码问题解决 把Windows下的工程导入到了Linux下Eclipse中,由于以前的工程代码,都是GBK编码的(Windows下的Eclipse 默认会去读取系统的编 ...

  4. Android布局大全

    Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面. 所有的布局方式都可以归类为ViewGroup的 ...

  5. Mac OS X中配置Apache

    我使用的Mac OS X版本是10.8.2,Mac自带了Apache环境. 启动Apache 设置虚拟主机 启动Apache 打开“终端(terminal)”,输入 sudo apachectl -v ...

  6. Unity3D ShaderLab 静态贴图光照模型

    Unity3D ShaderLab 静态贴图光照模型 其实在unity的光照模型中,我们可以把光照讯息烘培进入一个2D贴图,来实现着色器的光照效果. 下面是在unity中关闭灯光和打开灯光的对比效果. ...

  7. 第二个Sprint冲刺第一天

    讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 任务:第二次sprint前期把选择题的计时功能完成. 燃尽图: 开发感悟: 大三第一学期就快结束了,大家都为未来找工作而烦恼.班里的高手都去学校 ...

  8. ASP.NET定制简单的错误处理页面

    通常Web应用程序在发布后,为了给用户一个友好界面和使用体验,都会在错误发生时跳转至一个自定义的错误页面,而不是ASP.net向用户暴露出来的详细的异常列表. 简单的错误处理页面可以通过web.con ...

  9. javascript中 IE事件处理程序中try catch用法

    本例是学习中笔记 望指正批评! <input id='b1' type='button' value='按钮'/> <script> window.onload=functio ...

  10. UVa 10624 - Super Number

    题目大意 给定两个数n和m,如果长度为m的数满足对于每个i(n<=i<=m),数字的前i位都能被i整除,那么这个数就是超级数,求出字典序最小的符合要求的超级数. 分析 直接暴力搜索 #in ...