有關EXTJS中editgrid相關

       EXTJS 中editgrid是可編輯的一個很好用的grid表格吧。css

       在初始化editgrid綁定數據時,他能夠設置你要顯示的數據,要顯示幾列,列最前邊是否要有checkbox,以及它的樣式,點擊下能夠進入編輯狀態,在編輯那一列還能夠監聽事件作你要作的操做。數據庫

                

  
  
  
  
  1. //初始化EditGrid  
  2.     this.InitEditGrid = function () {  
  3.         var sm = new Ext.grid.CheckboxSelectionModel({});  
  4.  
  5.         var column = new Ext.grid.ColumnModel([  
  6.         //  { header: 'FID', dataIndex: 'FID'},  
  7.             sm,  
  8.             { header: '姓名', dataIndex: 'FName', width: 100, css: "text-align:left;", editor: new Ext.form.TextField() },  
  9.             { header: '數量', dataIndex: 'FNum', width: 100, css: "text-align:left;", editor: new Ext.form.TextField() },  
  10.             { header: '單價', dataIndex: 'FPrice', width: 100, css: "text-align:left;", editor: new Ext.form.TextField() },  
  11.             { header: '金額', dataIndex: 'FMount', width: 100, css: "text-align:left;", renderer: function (v) {  
  12.                 return "<font color=red> ¥</font>" + v  
  13.             }   
  14.             }  
  15.         ]);  
  16.  
  17.         tp = new Ext.data.Record.create([  
  18.             { name: "FID", type: "string", mapping: "FID" },  
  19.             { name: "FName", type: "string", mapping: "FName" },  
  20.             { name: "FNum", type: "decimal", mapping: "FNum" },  
  21.             { name: "FPrice", type: "decimal", mapping: "FPrice" },  
  22.             { name: "FMount", type: "decimal", mapping: "FMount" }  
  23.         ])  
  24.  
  25.         var reader = new Ext.data.JsonReader({}, tp);  
  26.  
  27.         gridStore = new Ext.data.Store({  
  28.             reader: reader,  
  29.             pruneModifiedRecords: true  
  30.         })  
  31.  
  32.         //初始化store  
  33.         gridStore.loadData([]);  
  34.  
  35.         //定義表格  
  36.         gridEdit = new Ext.grid.EditorGridPanel({  
  37.             width: 800,  
  38.             height: 300,  
  39.             cm: column,  
  40.             store: gridStore,  
  41.             clicksToEdit: 1,  
  42.             columnLines: true,  
  43.             sm: sm,  
  44.             listeners:  
  45.             {  
  46.                 afterEdit: function (a) {  
  47.                     var num = 0;  
  48.                     var price = 0;  
  49.  
  50.                     if (a.field == "FNum") {  
  51.                         num = a.value;  
  52.  
  53.                         price = gridStore.getRange()[a.row].data.FPrice;  
  54.                         if (price == "" || price == undefined) {  
  55.                             gridStore.getRange()[a.row].data.FMount = "";  
  56.                         }  
  57.                         else {  
  58.                             gridStore.getRange()[a.row].data.FMount = parseFloat(num) * parseFloat(price);  
  59.                             gridEdit.getView().refresh();  
  60.                         }  
  61.  
  62.                     }  
  63.                     else if (a.field == "FPrice") {  
  64.                         price = a.value;  
  65.  
  66.                         num = gridStore.getRange()[a.row].data.FNum;  
  67.                         if (num == "" || num == undefined) {  
  68.                             gridStore.getRange()[a.row].data.FMount = "";  
  69.                         }  
  70.                         else {  
  71.                             gridStore.getRange()[a.row].data.FMount = parseFloat(num) * parseFloat(price);  
  72.                             gridEdit.getView().refresh();  
  73.                         }  
  74.                     }  
  75.  
  76.                 }  
  77.             }  
  78.  
  79.         });  
  80.         //渲染  
  81.         gridEdit.render("editGrid");  
  82.     }  

他還能夠包含數據庫中沒有的數據,例如代碼中的FNum,FPrice ,FMount都不是數據庫中的哦,他們是能夠在本地直接添加,並且他是在afteredit事件以後發生的計算。app

相關文章
相關標籤/搜索