简体   繁体   English

如何以编程方式更改gridpanel的单元格的CSS

[英]How to programmatically change css of gridpanel's cell

I have two distinct gridpanels and throughout my code, whenever value of one of the cells in Grid1 changes I want to be able to change value of certain cells in the Grid2, How can I change the css of the second grid from within the Grid1. 我有两个截然不同的网格面板,并且在我的代码中,每当Grid1中某个单元格的值发生变化时,我都希望能够更改Grid2中某些单元格的值,那么如何从Grid1中更改第二个网格的css。

The following allows me to change the css for an entire row in Grid2 but I need to be able to change the css for a cell of Grid2 row: 2, column 3 以下内容使我可以更改Grid2中整个行的css,但我需要能够更改Grid2行的单元格的css:2,第3列

var Grid2Store= Ext.data.StoreManager.get("MainComparisonStore");
Grid2.getView().addRowCls(Grid2Store.getAt(2), 'orange-bar');

Get a hold of the element and you can use cellElement.addCls('orange-bar'); 获取元素的cellElement.addCls('orange-bar'); ,您可以使用cellElement.addCls('orange-bar'); . See Ext.dom.Element.addCls() documentation. 请参阅Ext.dom.Element.addCls()文档。 I put together a jsFiddle for you to see an example. 我整理了一个jsFiddle供您查看示例。 Just click the "Test" button in the grid toolbar. 只需单击网格工具栏中的“测试”按钮。

Here is the code that does the work. 这是完成工作的代码。 It is hard coded to add a class to column 1, row 1. 很难将代码添加到第1列第1行中。

var grid = Ext.getCmp('myGrid');
var column = grid.columns[1];
var record = grid.store.getAt(1);
var cell = grid.getView().getCell(record, column);
cell.addCls('orange-bar');

Here (Sencha Forum) is some discussion on how to get the cell. 这里(Sencha论坛)是有关如何获得细胞的一些讨论。 This is what I used to put together my example. 这就是我以前整理过的例子。 You can see how you could make a helper like getCell(rowIndex, columnIndex) pretty easily. 您可以看到如何轻松地使类似getCell(rowIndex,columnIndex)的助手成为可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM