Advertisement
fahmihilmansyah

extjs

Apr 28th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. //Membuat form grid
  2. var formGroup = Ext.create('Ext.form.Panel', {
  3. title : 'Form',
  4. layout : 'form',
  5. bodyStyle : 'padding: 7px',
  6. margins:'0px 0px 5px 0px',
  7. items: [
  8. {
  9. xtype : 'hidden',
  10. name : 'group_id',
  11. value : 0
  12. },
  13. {
  14. xtype : 'textfield',
  15. name : 'group_name',
  16. allowBlank : false,
  17. fieldLabel : 'Nama Group'
  18. }
  19. ],
  20. bbar : [
  21. {
  22. text : 'Save',
  23. iconCls : 'icon-disk',
  24. handler : function (btn) {
  25. var form = formGroup.getForm();
  26. var record = form.getRecord();
  27. var values = form.getValues();
  28. //alert(values);
  29. if (form.isValid()) {
  30. storeGroup.add(form.getValues());
  31. //reload storegroup
  32. storeGroup.reload();
  33. //reload storekontak
  34. comboGroup.reload();
  35. form.reset();
  36. } else {
  37. Ext.MessageBox.show({
  38. title : 'Error',
  39. msg : 'Form tidak valid',
  40. icon : Ext.MessageBox.ERROR,
  41. buttons : Ext.MessageBox.OK
  42. });
  43. }
  44. }
  45. },
  46. {
  47. text : 'Delete',
  48. iconCls : 'icon-delete',
  49. disabled: true,
  50. id : 'delGroup',
  51. handler : function (btn) {
  52. var form = formGroup.getForm();
  53. if (form.isValid()) {
  54. storeGroup.remove(gridGroup.getView().getSelectionModel().getSelection()[0]);
  55. form.reset();
  56. var button = Ext.getCmp('delGroup');
  57. button.setDisabled(true);
  58. } else {
  59. Ext.MessageBox.show({
  60. title : 'Error',
  61. msg : 'Form tidak valid',
  62. icon : Ext.MessageBox.ERROR,
  63. buttons : Ext.MessageBox.OK
  64. });
  65. }
  66. }
  67. },
  68. {
  69. text : 'Reset',
  70. iconCls : 'icon-error',
  71. handler : function (btn) {
  72. formGroup.getForm().reset();
  73. var button = Ext.getCmp('delGroup');
  74. button.setDisabled(true);
  75. }
  76. }
  77. ]
  78. });
  79.  
  80. //Membuat store untuk grid
  81. var storeGroup = Ext.create('Ext.data.Store', {
  82. autoSync : true,
  83. autoLoad : true,
  84. pageSize : 20,
  85. idProperty: 'group_id',
  86. idParam :'group_id',
  87. fields : [
  88. {
  89. name : 'group_id',
  90. type : 'number'
  91. },
  92. {
  93. name : 'group_name',
  94. type : 'string'
  95. }
  96. ],
  97. proxy : {
  98. type : 'ajax',
  99. api : {
  100. create : BASE_URL + 'index.php/coba1/group/save',
  101. read : BASE_URL + 'index.php/coba1/group/get',
  102. update : BASE_URL + 'index.php/coba1/group/update',
  103. destroy : BASE_URL + 'index.php/coba1/group/delete'
  104. },
  105. actionMethods : {
  106. read : 'POST',
  107. create : 'POST',
  108. update : 'POST',
  109. destroy: 'POST'
  110. },
  111. writer : {
  112. writeAllFields : true,
  113. type : 'json',
  114. root : 'data',
  115. encode: true
  116. },
  117. reader : {
  118. type: 'json',
  119. root: 'data',
  120. totalProperty : 'total',
  121. successProperty : 'success'
  122. }
  123. }
  124. });
  125.  
  126. //Membuat grid group
  127. var gridGroup = Ext.create('Ext.grid.Panel', {
  128. store : storeGroup,
  129. title : 'Grid',
  130. columns : [
  131. {
  132. text : 'ID',
  133. dataIndex : 'group_id',
  134. width : '17%'
  135. },
  136. {
  137. text : 'Nama',
  138. dataIndex : 'group_name',
  139. width : '82.9%'
  140. }
  141. ],
  142. listeners : {
  143. 'itemclick' : function (me, record, item, index, e, eOpts) {//mendengarkan event itemclick pada grid
  144. var form = formGroup.getForm();
  145. form.setValues(record.data);
  146. var button = Ext.getCmp('delGroup');
  147. button.setDisabled(false);
  148. }
  149. },
  150. bbar: Ext.create('Ext.PagingToolbar', {
  151. store: storeGroup,
  152. displayInfo : false
  153. })
  154. });
  155.  
  156. //Membuat panel dan menambahkan form dan grid group
  157. var group = Ext.create('Ext.panel.Panel', {
  158. title : 'Group',
  159. layout: {
  160. type :'vbox',
  161. padding:'5',
  162. align :'stretch'
  163. },
  164. defaults : {
  165. flex : 1
  166. },
  167. items : [formGroup, gridGroup]
  168. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement