2012-02-02 110 views
3

我有一個名爲「網格」的網格,並且onload中有插入到網格中的行。某些行將呈綠色將成功輸入行,而具有紅色背景顏色的行則會出現錯誤。我曾經在某個時間點工作過,但錯誤行會被添加到網格背景顏色爲紅色。然後,當我試圖添加一個新行來輸入新的數據,所有的行都變白了。然後,這一切都停止在一起工作。我試過更改行的背景顏色extjs4

store.insert(0, r).addClass('error-row'); 

Ext.fly(grid.getView().getRow(0)).addClass('error-row'); 

var cls ='error-row' 
          addRowClass : function(rowId, cls) { 
              var row = this.getRow(rowId); 
              if (row) { 
               this.fly(row).addClass(cls); 
              } 
             } 

grid.getView().getRowClass = function(record, index, rp ,store) { 

           return 'error-row'; 
            }; 

我不確定該怎麼做。

CSS

<style> 
    .error-row .x-grid-cell { 
    background-color: #990000 !important; 
    } 

    .new-row .x-grid-cell { 
    background-color: #F5F2F3 !important; 
    } 


</style> 

回答

4

的viewConfig屬性應該指向你在正確的方向 - 使用代碼來自外部的樣品電網,並補充說:

  • CLS字段定義一個類的記錄
  • viewConfig屬性到網格的配置

c頌詩是這樣的:

Ext.create('Ext.data.Store', { 
    storeId:'simpsonsStore', 
    fields:['name', 'email', 'phone', 'cls'], 
    data:{'items':[ 
     { 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224", "cls":"new-row" }, 
     { 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234", "cls":"new-row" }, 
     { 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244", "cls":"new-row" }, 
     { 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254", "cls": "error-row" } 
    ]}, 
    proxy: { 
     type: 'memory', 
     reader: { 
      type: 'json', 
      root: 'items' 
     } 
    } 
}); 

Ext.create('Ext.grid.Panel', { 
    title: 'Simpsons', 
    id: 'MyGrid', 
    store: Ext.data.StoreManager.lookup('simpsonsStore'), 
    columns: [ 
     { header: 'Name', dataIndex: 'name'}, 
     { header: 'Email', dataIndex: 'email', flex: 1}, 
     { header: 'Phone', dataIndex: 'phone'} 
    ], 
    viewConfig: { 
     getRowClass: function(record, rowIndex, rowParams, store){ 
      return record.get('cls'); 
     } 
    }, 
    height: 200, 
    width: 400, 
    renderTo: Ext.getBody() 
}); 
+0

的感謝! :)在官方文檔中找不到它! – 2012-02-07 12:42:26

+0

呀,單證是在這方面有點稀疏 - 它曾經(IIRC)是在內線2.X/3.X網常見問題,但我還沒有看到它過多提及在4.x的文檔。 – phatskat 2012-02-08 21:49:36

+0

看起來很奇怪,因爲模型中的視圖(類)具有特定的數據。 – 2012-05-16 15:52:56