Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Progress Column Grid Example</title>
<!-- ** CSS ** -->
<!-- base library -->
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="../ux/ProgressColumn.css" />
<!-- overrides to base library -->
<!-- page specific -->
<link rel="stylesheet" type="text/css" href="../shared/examples.css" />
<link rel="stylesheet" type="text/css" href="grid-examples.css" />
<style type=text/css>
.x-grid3-td-progress-cell .x-grid3-cell-inner {
font-weight: bold;
}
.x-grid3-td-progress-cell .high {
background: transparent url(../ux/images/progress-bg-red.gif) 0 -33px;
}
.x-grid3-td-progress-cell .medium {
background: transparent url(../ux/images/progress-bg-orange.gif) 0 -33px;
}
.x-grid3-td-progress-cell .low {
background: transparent url(../ux/images/progress-bg-green.gif) 0 -33px;
}
.x-grid3-td-progress-cell .ux-progress-cell-foreground {
color: #fff;
}
</style>
<!-- ** Javascript ** -->
<!-- ExtJS library: base/adapter -->
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<!-- ExtJS library: all widgets -->
<script type="text/javascript" src="../../ext-all.js"></script>
<!-- overrides to base library -->
<script type="text/javascript" src="../ux/ProgressColumn.js"></script>
<!-- page specific -->
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
// sample static data for the store
var myData = [
['3m Co',71.72,70.64,'9/1 12:00am'],
['Alcoa Inc',29.01,24.5,'9/1 12:00am'],
['Altria Group Inc',83.81,42.1,'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;
}
// create the data store
var store = new Ext.data.ArrayStore({
fields: [
{name: 'company'},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
],
data: 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'},
new Ext.ux.ProgressColumn({
header: '% Change',
width: 105,
dataIndex: 'change',
divisor: 'price',
align: 'center',
renderer: function(value, meta, record, rowIndex, colIndex, store, pct) {
return Ext.util.Format.number(pct, "0.00%");
}
}),
{header: 'Last Updated', width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
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');
});
</script>
</head>
<body>
<h1>Progress Column Grid Example</h1>
<div id="grid-example"></div>
</body>
</html>