Extjs根據(jù)條件設(shè)置表格某行背景色示例
話(huà)不多說(shuō),貼上代碼
html代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../extjs3/resources/css/ext-all.css" rel="external nofollow" />
<script type="text/javascript" src="../extjs3/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../extjs3/ext-all.js"></script>
<script type="text/javascript" src="array-grid.js"></script>
<style type="text/css">
.<span style="font-family: Arial, Helvetica, sans-serif;">my_row_class</span><span style="font-family: Arial, Helvetica, sans-serif;">{ background:gray;}</span>
</style>
</head>
<body>
<div id="grid-example"></div>
</body>
</html>
js代碼,其中應(yīng)-----隔開(kāi)的代碼即為關(guān)鍵代碼,自己分析吧:
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
// sample static data for the store
var myData = [
['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],
['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],
['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],
['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am']
];
/**
* Custom function used for column renderer
* @param {Object} val
*/
function change(val) {
if (val > 0) {
return '<span style="color:green;">' + val + '</span>';
} else if (val < 0) {
return '<span style="color:red;">' + val + '</span>';
}
return val;
}
/**
* Custom function used for column renderer
* @param {Object} val
*/
function pctChange(val) {
if (val > 0) {
return '<span style="color:green;">' + val + '%</span>';
} else if (val < 0) {
return '<span style="color:red;">' + val + '%</span>';
}
return val;
}
// create the data store
var store = new Ext.data.ArrayStore({
fields: [
{name: 'company'},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'pctChange', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]
});
// manually load local data
store.loadData(myData);
// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{
id :'company',
header : 'Company',
width : 160,
sortable : true,
dataIndex: 'company'
},
{
header : 'Price',
width : 75,
sortable : true,
renderer : 'usMoney',
dataIndex: 'price'
},
{
header : 'Change',
width : 75,
sortable : true,
renderer : change,
dataIndex: 'change'
},
{
header : '% Change',
width : 75,
sortable : true,
renderer : pctChange,
dataIndex: 'pctChange'
},
{
header : 'Last Updated',
width : 85,
sortable : true,
renderer : Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex: 'lastChange'
}
],viewConfig : {forceFit:true
//------------------------------------------------
,getRowClass : function(record,rowIndex,rowParams,store){
if("3m Co"==record.get('company')){
return 'my_row_class';
}
}
//------------------------------------------------
},
stripeRows: true,
autoExpandColumn: 'company',
height: 350,
width: 600,
title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});
// render the grid to the specified div in the page
grid.render('grid-example');
});
相關(guān)文章
extjs 學(xué)習(xí)筆記(一) 一些基礎(chǔ)知識(shí)
相信很多人對(duì)使用js進(jìn)行客戶(hù)端的編程比較頭大,其實(shí)現(xiàn)在已經(jīng)有了很多優(yōu)秀的js庫(kù),可以大大簡(jiǎn)化js編程的工作量,其中,jquery和extjs就是兩款非常優(yōu)秀的js庫(kù)。2009-10-10
一個(gè)簡(jiǎn)單的Ext.XTemplate的實(shí)例代碼
把省份與城市以樹(shù)的形式輸出的Ext.XTemplate的實(shí)例代碼,需要的朋友可以參考下2012-03-03
學(xué)習(xí)ExtJS 訪問(wèn)容器對(duì)象
ExtJS 訪問(wèn)容器對(duì)象使用說(shuō)明,需要的朋友可以參考下。2009-10-10
extjs 學(xué)習(xí)筆記(三) 最基本的grid
extjs的一個(gè)亮點(diǎn)就是提供了豐富的UI,使得沒(méi)有藝術(shù)細(xì)胞的程序員也能做出絢麗的界面。把所有的UI集中到一起,有好處也有壞處,好處是有了統(tǒng)一的風(fēng)格和接口,壞處是js文件過(guò)于龐大,使用extjs的最小集合也超過(guò)了500k,所以在有些項(xiàng)目中并不適用。2009-10-10
Extjs列表詳細(xì)信息窗口新建后自動(dòng)加載解決方法
有時(shí)候我們?cè)谛陆斜碇械囊豁?xiàng)后需要進(jìn)入立刻進(jìn)入詳細(xì)信息的編輯頁(yè)面,為了使得操作簡(jiǎn)便,一般設(shè)定自動(dòng)導(dǎo)向。2010-04-04
Extjs學(xué)習(xí)筆記之三 extjs form更多的表單項(xiàng)
本文接著上講Extjs學(xué)習(xí)筆記之二 Extjs之Form介紹Extjs的表單。Extjs除了類(lèi)似普通的html form的表單項(xiàng)之外,還有一些功能更為豐富實(shí)用的表單項(xiàng)。2010-01-01
ExtJS TabPanel beforeremove beforeclose使用說(shuō)明
ExtJS 關(guān)閉TabPanel內(nèi)的Panel時(shí)使用TabPanel的'beforeremove’和其內(nèi)的Panel的'beforeclose’事件彈出關(guān)閉確認(rèn)提示對(duì)話(huà)框2010-03-03

