5a61c15355d8e2f7e7c51e376f98f42376733e44.svn-base 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Cell Editing in DataGrid - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Cell Editing in DataGrid</h2>
  14. <p>Click a cell to start editing.</p>
  15. <div style="margin:20px 0;"></div>
  16. <table id="dg" class="easyui-datagrid" title="Cell Editing in DataGrid" style="width:700px;height:auto"
  17. data-options="
  18. iconCls: 'icon-edit',
  19. singleSelect: true,
  20. url: 'datagrid_data1.json',
  21. method:'get',
  22. onClickCell: onClickCell
  23. ">
  24. <thead>
  25. <tr>
  26. <th data-options="field:'itemid',width:80">Item ID</th>
  27. <th data-options="field:'productid',width:100,editor:'text'">Product</th>
  28. <th data-options="field:'listprice',width:80,align:'right',editor:{type:'numberbox',options:{precision:1}}">List Price</th>
  29. <th data-options="field:'unitcost',width:80,align:'right',editor:'numberbox'">Unit Cost</th>
  30. <th data-options="field:'attr1',width:250,editor:'text'">Attribute</th>
  31. <th data-options="field:'status',width:60,align:'center',editor:{type:'checkbox',options:{on:'P',off:''}}">Status</th>
  32. </tr>
  33. </thead>
  34. </table>
  35. <script type="text/javascript">
  36. $.extend($.fn.datagrid.methods, {
  37. editCell: function(jq,param){
  38. return jq.each(function(){
  39. var opts = $(this).datagrid('options');
  40. var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
  41. for(var i=0; i<fields.length; i++){
  42. var col = $(this).datagrid('getColumnOption', fields[i]);
  43. col.editor1 = col.editor;
  44. if (fields[i] != param.field){
  45. col.editor = null;
  46. }
  47. }
  48. $(this).datagrid('beginEdit', param.index);
  49. for(var i=0; i<fields.length; i++){
  50. var col = $(this).datagrid('getColumnOption', fields[i]);
  51. col.editor = col.editor1;
  52. }
  53. });
  54. }
  55. });
  56. var editIndex = undefined;
  57. function endEditing(){
  58. if (editIndex == undefined){return true}
  59. if ($('#dg').datagrid('validateRow', editIndex)){
  60. $('#dg').datagrid('endEdit', editIndex);
  61. editIndex = undefined;
  62. return true;
  63. } else {
  64. return false;
  65. }
  66. }
  67. function onClickCell(index, field){
  68. if (endEditing()){
  69. $('#dg').datagrid('selectRow', index)
  70. .datagrid('editCell', {index:index,field:field});
  71. editIndex = index;
  72. }
  73. }
  74. </script>
  75. </body>
  76. </html>