PanelController.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Ext.define('uas.view.grid.rowManager.PanelController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.row-manager',
  4. onRowInsert: function() {
  5. var me = this,
  6. grid = me.getView(),
  7. selectionModel = grid.getSelectionModel(),
  8. currentPosition;
  9. if(selectionModel.hasSelection()) {
  10. currentPosition = me.getSelectedPosition();
  11. me.insertRow(currentPosition.rowIdx, 1);
  12. }else {
  13. Ext.toast('未选中行')
  14. }
  15. },
  16. onRowAdd: function() {
  17. this.addRow(1);
  18. },
  19. onRowRemove: function() {
  20. var me = this,
  21. grid = me.getView(),
  22. selectionModel = grid.getSelectionModel(),
  23. currentPosition;
  24. if(selectionModel.hasSelection()) {
  25. currentPosition = me.getSelectedPosition();
  26. me.removeRow(currentPosition.rowIdx);
  27. }else {
  28. Ext.toast('未选中行')
  29. }
  30. },
  31. getSelectedPosition: function() {
  32. var me = this,
  33. grid = me.getView(),
  34. selectionModel = grid.getSelectionModel(),
  35. currentPosition;
  36. if(selectionModel.hasSelection()) {
  37. currentPosition = selectionModel.getCurrentPosition();
  38. return currentPosition;
  39. }else {
  40. return null;
  41. }
  42. },
  43. insertRow: function(idx, num) {
  44. var me = this,
  45. grid = me.getView(),
  46. store = grid.getStore(),
  47. datas = [];
  48. Ext.Array.each(new Array(num), function() {
  49. datas.push({});
  50. })
  51. store.insert(idx, datas);
  52. },
  53. addRow: function(num) {
  54. var me = this,
  55. grid = me.getView(),
  56. store = grid.getStore(),
  57. datas = [];
  58. Ext.Array.each(new Array(num), function() {
  59. datas.push({});
  60. })
  61. store.add(datas);
  62. },
  63. removeRow: function(idx) {
  64. var me = this,
  65. grid = me.getView(),
  66. store = grid.getStore();
  67. store.removeAt(idx);
  68. },
  69. })