2012-08-28 80 views
2

我有一個商店,其字段中包含「Y」或「N」字段。我想採用Y或N值,並在網格中放置一些綠色或紅色圖標,而不是文本。我一直在使用條件渲染函數,但我無法弄清楚如何根據值顯示圖標。到目前爲止,我有Extjs 4網格:根據商店文本值在單元格中放置圖標

initComponent: function() { 
    this.columns=[ 
     {header: 'PreReq', dataIndex: 'PreReq', width: 50, 
      renderer: function(value){ 
       if(value == 'Y'){ 
        //some code to put green icon in this cell 
       } 
       else if(value =='N'){ 
        //come code to put red icon in this cell 
       } 
       else{ 
        //some code to put error icon in this cell 
       } 
      } 
     } 
    ]; 
    this.callParent(arguments); 
} 

回答

9

它是那麼容易,因爲:

return '<img src="..." />'; 

或者如果你喜歡的CSS的方式,你可以這樣做:

renderer: function(value, metadata, record) 
{ 
    metadata.tdCls = 'yes-icon' 
} 
+1

或者你可以使用'metaData.tdClass 「如果你願意這樣做的話。 – Izhaki

+0

@Izhaki:值得再增加一個答案。我喜歡它 – zerkms

+2

認爲一個完整的答案比兩個更好 - 所以我把它與你的合併。 – Izhaki