2011-03-03 80 views
0

如果單元格不可編輯,我需要更改單元格的顏色。在isCellEditable方法中改變單元格的顏色ExtJS

我不想爲此用戶渲染器,因爲我在isCellEditable方法中進行了大量的驗證。

如果我從渲染器調用了兩次isCellEditable方法,這個方法將被調用,並且這將是一個perforamance命中。

任何幫助表示讚賞。

下面是我的代碼:

var grid = new Ext.grid.EditorGridPanel({ 

    store: store, 

    id: 'editorgrid', 
    columnLines : true, 

    //more properties.. 

    cm: new Ext.grid.ColumnModel({ 
     isCellEditable: function(colIndex, rowIndex) { 
      if(colIndex == 1) { 
       //before returning false I want to change the color of this cell i.e want to make it grayed out  
       return false; 
      } 
     } 
    }) 
}); 

回答

0

爲什麼你不希望使用渲染器呢?這是渲染器的作用。您可以輕鬆地將渲染器添加到列中,並在此渲染器中爲單元的元對象添加屬性,以根據可編輯狀態更改顏色。

var myCellRenderer = function(value, metaData, record) { 

    //metaData.css : String : A CSS class name to add to the cell's TD element. 
    //metaData.attr : String : An html attribute definition string to apply to 
    //       the data container element within the table 
    //       cell (e.g. 'style="color:red;"'). 
    metaData.css = 'name-of-css-class'; 
    return value; 

}; 

直接從ExtJS的電網常見問題解答:http://www.sencha.com/learn/Ext_FAQ_Grid

+0

嗨克里斯,感謝您的回覆 – atm 2011-03-07 05:05:15

+0

克里斯 - 嗨,你的答覆這裏.The問題是我在做很多的isCellEditable使用AJAX服務器端驗證的感謝方法,並基於我返回值真或假,使一個特殊的單元格可編輯或不可編輯。如果它是不可編輯的,即reture false,那麼它應顯示爲灰色color.Now,如果我使用渲染器,我需要調用從下面的renderer方法中獲取iscelleditable方法,這是知道單元格是否可編輯的唯一方法,並且它又會再次調用所有服務器端驗證,並且會影響感謝 – atm 2011-03-07 05:22:12

+0

你真的通過ajax調用評估每個單元的可編輯性,還是我明白錯誤?如果是這樣的話,在加載商店時在服務器端執行一次運行評估,並且仍然使用根據商店中的值對單元格進行着色的渲染器,可能會更有效。 – ChrisR 2011-03-07 08:13:45