tablegrid-edit-ajax.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. define(function (require) {
  2. return function (context) {
  3. var $grid1, $grid2, dictId, dictCode;
  4. function refreshGrid2(rowid) {
  5. var row = $grid1.yvgrid('rowData', rowid);
  6. if (!row) {
  7. $.yvan.msg('请先选择一行数据');
  8. return;
  9. }
  10. //如果是可编辑表格,不能直接用 dataAdapter 读取(会有bug)
  11. //这里是自己用 ajax 方法读取数据的
  12. $grid2.yvgrid('showLoading');
  13. $.yvan.ajax({
  14. url: demoApi('/sysDict/queryList'),
  15. data: {dictCode: row.dictCode},
  16. success: function (root) {
  17. dictId = row.dictId;
  18. dictCode = row.dictCode;
  19. $grid2.yvgrid('reload', {data: root.data});
  20. },
  21. complete: function () {
  22. $grid2.yvgrid('hideLoading');
  23. }
  24. });
  25. }
  26. return {
  27. west: {
  28. border: false,
  29. width: 450,
  30. split: true,
  31. items: {
  32. xtype: 'yvgrid',
  33. url: demoApi('/sysDict/query'),
  34. mtype: 'post',
  35. onRender: function () {
  36. $grid1 = $(this);
  37. },
  38. toolbar: {
  39. xtype: 'toolbar', title: '字典列表'
  40. },
  41. idField: 'dictId',
  42. columns: [[
  43. {field: 'dictId', title: 'dictId'},
  44. {
  45. field: 'dictType', title: '字典类别',
  46. formatter: [{id: '0', text: '用户字典'}, {id: '1', text: '系统字典'}]
  47. },
  48. {field: 'dictCode', title: '字典编号'},
  49. {field: 'dictDesc', title: '字典描述'}
  50. ]],
  51. onSelectRow: function (rowid) {
  52. refreshGrid2(rowid);
  53. }
  54. }
  55. },
  56. center: {
  57. border: false,
  58. items: {
  59. xtype: 'yvgrid',
  60. onRender: function () {
  61. $grid2 = $(this);
  62. },
  63. editable: true,
  64. autoSizeColumns: false,
  65. editOnSelected: true,
  66. idField: 'dictList',
  67. toolbar: {
  68. xtype: 'toolbar', title: '系统字典详情'
  69. },
  70. onRowAppend: function (rowid, rowdata, commit) {
  71. var data = $.extend({
  72. dictId: dictId,
  73. dictCode: dictCode,
  74. }, rowdata);
  75. delete data.createAt;
  76. delete data.updateAt;
  77. $.yvan.postJson({
  78. url: demoApi('/sysDict/insertList'),
  79. data: data,
  80. success: function () {
  81. commit(true);
  82. $.yvan.msg('操作成功');
  83. },
  84. error: function () {
  85. $.yvan.msg('操作失败');
  86. }
  87. });
  88. },
  89. onRowUpdate: function (rowid, rowdata, commit) {
  90. delete rowdata.createAt;
  91. delete rowdata.updateAt;
  92. rowdata.dictId = dictId;
  93. rowdata.dictCode = dictCode;
  94. $.yvan.postJson({
  95. url: demoApi('/sysDict/updateList'),
  96. data: {
  97. dictId: dictId,
  98. dictList: rowid,
  99. data: rowdata
  100. },
  101. success: function () {
  102. commit(true);
  103. $.yvan.msg('更新成功');
  104. },
  105. error: function () {
  106. $.yvan.msg('更新失败');
  107. }
  108. });
  109. commit(true);
  110. },
  111. onRowDelete: function (rowid, commit) {
  112. $.yvan.postJson({
  113. url: demoApi('/sysDict/deleteList'),
  114. data: {dictId: dictId, dictCode: dictCode, dictList: rowid},
  115. success: function () {
  116. commit(true);
  117. $.yvan.msg('操作成功');
  118. },
  119. error: function () {
  120. $.yvan.msg('操作失败');
  121. }
  122. });
  123. },
  124. columns: [[
  125. {field: 'dictId', hidden: true},
  126. {field: 'dictCode', hidden: true},
  127. {
  128. field: 'dictList', title: '字典内容', width: 100,
  129. editor: {
  130. xtype: 'textbox',
  131. validType: 'length[1,255]', required: true
  132. }
  133. },
  134. {
  135. field: 'dictValue', title: '字典值', width: 100,
  136. editor: {
  137. xtype: 'textbox',
  138. validType: 'length[1,50]', required: true
  139. }
  140. },
  141. {
  142. field: 'udf1', title: '自定义1', width: 100,
  143. editor: {
  144. xtype: 'textbox'
  145. }
  146. },
  147. {
  148. field: 'udf2', title: '自定义2', width: 100,
  149. editor: {
  150. xtype: 'textbox'
  151. }
  152. },
  153. {
  154. field: 'udf3', title: '自定义3', width: 100,
  155. editor: {
  156. xtype: 'textbox'
  157. }
  158. },
  159. ]]
  160. }
  161. }
  162. };
  163. };
  164. });