简体   繁体   English

如何在Ext4的树节点中添加CSS类?

[英]How do I add a css class to a tree node in Ext4?

I would like to highlight some of the nodes in an Ext.tree.Panel. 我想突出显示Ext.tree.Panel中的某些节点。

In Ext3 I accomplished this by adding a class to the tree node ui object: 在Ext3中,我通过向树节点ui对象添加一个类来实现此目的:

// add a class with to highlight the node
myTreeNode.getUI().addClass('highlightclass');

// remove the class to remove the highlighting
myTreeNode.getUI().removeClass('highlightclass');

What is the equivalent in Ext4? Ext4中的等效功能是什么? I have been able to change the icon by setting the iconCls field of my node model, but I would really like to be able to set a class that allows me to highlight the whole node. 我可以通过设置节点模型的iconCls字段来更改图标,但是我真的很希望能够设置一个类,使我可以突出显示整个节点。

Here is the answer I found to my own question: 这是我对自己的问题的答案:

// add a css class to a specific tree node
myTreePanel.getView().addRowCls(myTreeNode,'highlightclass');

// remove a css class from a specific tree node
myTreePanel.getView().removeRowCls(myTreeNode,'highlightclass');

While the selected answer may work, in my version of ExtJS (4.0.7) as soon as I expand or collapse a node in my tree panel the css classes were all reset. 尽管选择的答案可能有效,但在我的ExtJS版本(4.0.7)中,一旦在树形面板中展开或折叠节点,css类都将全部重置。 I believe the more permanent way to fix this would be 我相信更永久的解决方法是

myTreeNode.set('cls', 'highlightclass');

This will add your class to the specific tree node's td.x-grid-cell DOM element. 这会将您的类添加到特定树节点的td.x-grid-cell DOM元素。

Hope that helps 希望能有所帮助

To accomplish this you will need to think of the tree instead as a treegrid. 为此,您需要将树视为树形网格。 Set up a columns definition for your tree with only one column, hide the header of the column and add a renderer to the column. 为仅包含一列的树设置一列定义,隐藏该列的标题并将渲染器添加到该列。

after that you can define your renderer like so with a css class defined for your highlighted rows and probably an attribute on the row model to tell which rows should be highlighted: 之后,您可以像这样定义渲染器,为突出显示的行定义一个css类,并可能在行模型上定义一个属性来告诉应该突出显示哪些行:

renderer: function(value, metaData){
    if (whatever you want here as a condition) {
        metaData.tdCls = "x-grid-row-alt-mine";
    }
    return value;
}

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

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