editable.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Editable TreeGrid - 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>Editable TreeGrid</h2>
  14. <p>Select one node and click edit button to perform editing.</p>
  15. <div style="margin:20px 0;">
  16. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="edit()">Edit</a>
  17. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()">Save</a>
  18. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancel()">Cancel</a>
  19. </div>
  20. <table id="tg" class="easyui-treegrid" title="Editable TreeGrid" style="width:700px;height:250px"
  21. data-options="
  22. iconCls: 'icon-ok',
  23. rownumbers: true,
  24. animate: true,
  25. collapsible: true,
  26. fitColumns: true,
  27. url: 'treegrid_data2.json',
  28. method: 'get',
  29. idField: 'id',
  30. treeField: 'name',
  31. showFooter: true
  32. ">
  33. <thead>
  34. <tr>
  35. <th data-options="field:'name',width:180,editor:'text'">Task Name</th>
  36. <th data-options="field:'persons',width:60,align:'right',editor:'numberbox'">Persons</th>
  37. <th data-options="field:'begin',width:80,editor:'datebox'">Begin Date</th>
  38. <th data-options="field:'end',width:80,editor:'datebox'">End Date</th>
  39. <th data-options="field:'progress',width:120,formatter:formatProgress,editor:'numberbox'">Progress</th>
  40. </tr>
  41. </thead>
  42. </table>
  43. <script type="text/javascript">
  44. function formatProgress(value){
  45. if (value){
  46. var s = '<div style="width:100%;border:1px solid #ccc">' +
  47. '<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
  48. '</div>';
  49. return s;
  50. } else {
  51. return '';
  52. }
  53. }
  54. var editingId;
  55. function edit(){
  56. if (editingId != undefined){
  57. $('#tg').treegrid('select', editingId);
  58. return;
  59. }
  60. var row = $('#tg').treegrid('getSelected');
  61. if (row){
  62. editingId = row.id
  63. $('#tg').treegrid('beginEdit', editingId);
  64. }
  65. }
  66. function save(){
  67. if (editingId != undefined){
  68. var t = $('#tg');
  69. t.treegrid('endEdit', editingId);
  70. editingId = undefined;
  71. var persons = 0;
  72. var rows = t.treegrid('getChildren');
  73. for(var i=0; i<rows.length; i++){
  74. var p = parseInt(rows[i].persons);
  75. if (!isNaN(p)){
  76. persons += p;
  77. }
  78. }
  79. var frow = t.treegrid('getFooterRows')[0];
  80. frow.persons = persons;
  81. t.treegrid('reloadFooter');
  82. }
  83. }
  84. function cancel(){
  85. if (editingId != undefined){
  86. $('#tg').treegrid('cancelEdit', editingId);
  87. editingId = undefined;
  88. }
  89. }
  90. </script>
  91. </body>
  92. </html>