tablegrid.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. define(function (require) {
  2. return function () {
  3. var $grid;
  4. return {
  5. center: {
  6. border: false,
  7. items: {
  8. xtype: 'yvgrid',
  9. onRender: function () {
  10. $grid = $(this);
  11. },
  12. filter: true,
  13. sortable: true,
  14. pagination: true,
  15. border: false,
  16. checkbox: true,
  17. pageList: [2, 5, 20, 40, 50],
  18. toolbar: {
  19. xtype: 'toolbar',
  20. height: '38',
  21. title: '工具条',
  22. items: [
  23. {
  24. text: '本地数据', iconCls: 'fa fa-plus-circle',
  25. onClick: function () {
  26. $grid.yvgrid('showLoading');
  27. $.yvan.ajax({
  28. url: demoApi('/queryUserNoPage'),
  29. success: function (root) {
  30. $grid.yvgrid('reload', {
  31. data: root.data
  32. });
  33. $grid.yvgrid('hideLoading');
  34. }
  35. });
  36. }
  37. },
  38. {
  39. text: '远程查询', iconCls: 'fa fa-plus-circle',
  40. onClick: function () {
  41. $grid.yvgrid('reload', {
  42. url: demoApi('/queryUser'),
  43. queryParams: {
  44. 'a': 1,
  45. 'b': 2
  46. }
  47. });
  48. }
  49. },
  50. {
  51. text: '空刷新', iconCls: 'fa fa fa-pencil-square-o',
  52. onClick: function () {
  53. $grid.yvgrid('reload');
  54. }
  55. },
  56. {
  57. text: '清空筛选', iconCls: 'fa fa-filter',
  58. onClick: function () {
  59. $grid.yvgrid('clearfilters');
  60. }
  61. }, '|',
  62. {
  63. text: '选择一行', iconCls: 'fa fa fa-pencil-square-o',
  64. onClick: function () {
  65. $grid.yvgrid('selectRow', 1);
  66. }
  67. }, '|',
  68. {
  69. text: '获取勾选', iconCls: 'fa fa-checked', onClick: function () {
  70. var data = $grid.yvgrid('getChecked');
  71. $.yvan.alert('<pre>' +
  72. JSON.stringify(data, null, ' ') +
  73. '</pre>');
  74. }
  75. },
  76. {
  77. text: '设置勾选', iconCls: 'fa fa-check', onClick: function () {
  78. $grid.yvgrid('setChecked', ['ADMIN_1', 'USER0000006', 'USER0000025']);
  79. }
  80. },
  81. {
  82. text: '清空勾选', iconCls: 'fa fa-checked', onClick: function () {
  83. $grid.yvgrid('checkedClear');
  84. }
  85. },
  86. {
  87. text: '全勾选', iconCls: 'fa fa-checked', onClick: function () {
  88. $grid.yvgrid('checkedAll');
  89. }
  90. },
  91. {
  92. text: '获取行', iconCls: 'fa fa-save', onClick: function () {
  93. var data = $grid.yvgrid('rowData');
  94. $.yvan.alert('<pre>' +
  95. JSON.stringify(data, null, ' ') +
  96. '</pre>');
  97. }
  98. }, {
  99. text: 'rowIndex', iconCls: 'fa fa-times', onClick: function () {
  100. var rowIndex = $grid.yvgrid('rowIndex');
  101. $.yvan.msg('rowIndex:' + rowIndex);
  102. }
  103. }, {
  104. text: 'boundIndex', iconCls: 'fa fa-times', onClick: function () {
  105. var rowBoundIndex = $grid.yvgrid('rowBoundIndex');
  106. $.yvan.msg('rowBoundIndex:' + rowBoundIndex);
  107. }
  108. }, {
  109. text: 'showError', iconCls: 'fa fa-times', onClick: function () {
  110. var rowBoundIndex = $grid.yvgrid('rowBoundIndex');
  111. $grid.yvgrid('showError', rowBoundIndex, "idName", "这里显示一个单元格异常,这里显示一个单元格异常!<br />内部用BR换行!内容不要过长!");
  112. }
  113. }, {
  114. text: 'getData', iconCls: 'fa fa-times', onClick: function () {
  115. var datas = $grid.yvgrid('getData');
  116. console.log(datas);
  117. }
  118. }, '|', {
  119. text: '关闭', iconCls: 'fa fa-times-circle fa-lg', onClick: function () {
  120. App.closeMe(this);
  121. }
  122. }
  123. ]
  124. },
  125. idField: 'userId',
  126. autoSizeColumns: true,
  127. onBeforeSelect: function (newIndex, oldIndex, event) {
  128. //return (newIndex % 2 === 1);
  129. },
  130. onSelect: function (rowid, row) {
  131. console.log('onSelect rowid:' + rowid + ", row:", row);
  132. },
  133. onCheckedChange: function (rowid, value, row) {
  134. console.log('onCheckedChange rowid:' + rowid + ", value:" + value + ", row:", row);
  135. },
  136. columns: [[
  137. { field: 'userId', hidden: true },
  138. { field: 'loginName', title: '登录名', sortable: false, minwidth: 100 },
  139. { field: 'staffName', title: '职员姓名', minwidth: 100 },
  140. { field: 'userType', title: '用户类型', minwidth: 100, formatter: [{ id: 'A', text: '系统管理员' }, { id: 'E', text: '企业用户' }, { id: 'N', text: '仓库用户' }] },
  141. { field: 'gender', title: '性别', minwidth: 100, formatter: [{ id: 'M', text: '男' }, { id: 'F', text: '女' }] },
  142. { field: 'duty', title: '职务', minwidth: 100 },
  143. { field: 'mobile', title: '手机', minwidth: 100 },
  144. { field: 'uiStyle', title: '界面风格', minwidth: 100, formatter: [{ id: 'light', text: '浅色风格' }, { id: 'dark', text: '暗色风格' }] },
  145. { field: 'loginCount', title: '登录次数', minwidth: 100, type: 'number' },
  146. { field: 'lastLoginTime', title: '最后登录时间', minwidth: 100, type: 'date', formatter: fmtDate },
  147. { field: 'userState', title: '是否锁定', minwidth: 100, formatter: [{ id: '0', text: '锁定' }, { id: '1', text: '正常' }] },
  148. { field: 'beActive', title: '启用状态', minwidth: 100, type: 'bool', on: 'Y', off: 'N' },
  149. { field: 'createAt', title: '创建时间', minwidth: 100, type: 'date', formatter: fmtDate },
  150. { field: 'updateAt', title: '最后更新时间', minwidth: 100, type: 'date', formatter: fmtDate }
  151. ]]
  152. }
  153. }
  154. };
  155. };
  156. });