標籤:extjs grid extjs4.2
本教程知識點是如何改變Grid中某行記錄背景顏色,顯示結果片:
650) this.width=650;" src="http://www.itdatum.net/uploads/webui/2014/0811/20140811002.png" />
範例程式碼:http://www.itdatum.net/webui/extjs/2014/08/7930.html
線上示範:http://www.itdatum.net/online/extjs/examples-itdatum/grid-summary-2/grid-summary-2.html
實現方式是為Grid配置viewConfig屬性,自訂實現getRowClass函數。
-
record: 當前待渲染行資料Model,類型為:Ext.data.Model
-
rowIndex: 當前待渲染行數,類型為:Number
-
rowParams: 渲染時傳入到行模板中的設定物件,通過它可以為行體定製樣式,該對象只在enableRowBody為true時才生效
-
store : 當前資料Store,類型為:Ext.data.Store
-
return : 傳回型別為:String,返回結果為待渲染的HTML代碼。
核心代碼如下:
View:UserList.js
Ext.define(‘Itdatum.view.UserList‘ ,{ extend: ‘Ext.grid.Panel‘, alias : ‘widget.userlist‘, title : ‘All Users‘, store: ‘UserStore‘, /* getRowClass:更改行樣式 */ viewConfig:{getRowClass:changeRowClass}, initComponent: function() { this.columns = [ {header: ‘Name‘, dataIndex: ‘name‘, width:100}, {header: ‘Idno‘, dataIndex: ‘idno‘, width:150}, {header: ‘Gender‘, dataIndex: ‘type‘, width:60,renderer : function(v) {return v==1 ? ‘男‘ : ‘女‘;}}, {header: ‘Birthday‘, dataIndex: ‘birthday‘, width:120}, {header: ‘Email‘, dataIndex: ‘email‘, flex: 1} ]; this.callParent(arguments); }});
函數:changeRowClass
function changeRowClass(record, rowIndex, rowParams, store){ if (record.get("type") == "1") { return ‘x-grid-record-yellow‘; }}自訂樣式:x-grid-record-yellow
tr.x-grid-record-yellow .x-grid-td { background: YELLOW;}
本文出自 “Itdatum” 部落格,請務必保留此出處http://1162235.blog.51cto.com/1152235/1538703