我定义了一个grid,并添加了rowclick事件的监听,可是不知道该如何修改这一行的背景色。请教高手一下。代码如下:
grid.addListener('rowclick',function(grid,rowIndex,event){
// 这里的代码不知道该如何写了,才能改变这行的背景色。
// 当然,当我点击别的行时,这一行的背景颜色要改变到每点击之前的默认颜色
});
1条回答 默认 最新
- zhoujuan520 2009-03-31 09:03关注
我帮你实现了,给我分吧
[code="js"]
Ext.onReady(function() {
var myData = [
['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'],
['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am']
];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; } 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; } var store = new Ext.data.SimpleStore({ fields: [ {name: 'company'}, {name: 'price', type: 'float'}, {name: 'change', type: 'float'}, {name: 'pctChange', type: 'float'}, {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'} ] }); store.loadData(myData); 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'} ], stripeRows: true, autoExpandColumn: 'company', enableHdMenu : true, height:350, width:600, title:'Array Grid' }); grid.render(Ext.getBody()); grid.on('rowclick',function(grid,rowIndex,event){ var node = event.target; while(node.tagName != 'TR'){ node = node.parentNode; if(node.tagName == 'TR'){ break; } } var elDiv = node.parentNode.parentNode.parentNode.parentNode; for(var i = 0; i<elDiv.childNodes.length;i++){ elDiv.childNodes[i].childNodes[0].childNodes[0].childNodes[0].style.cssText="background-color:"; } node.style.cssText="background-color:red"; });
})
[/code]
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报