简体   繁体   English

Sencha GXT Grid 按名称而不是按索引工作

[英]Sencha GXT Grid work by name instead by index

I'm trying to modify the column header menu of my grid in GXT Sencha 4. I want to add new menu items to specific column headers.我正在尝试在 GXT Sencha 4 中修改我的网格的 header 列菜单。我想将新菜单项添加到特定的列标题。

from the gxt web site:来自 gxt web 网站:

final Grid<Employee> grid = new Grid<Employee>(listStore, columnModel, new GridView<Employee>() {
    @Override
    protected Menu createContextMenu(int colIndex) {
        Menu menu = super.createContextMenu(colIndex);
        menu.add(new MenuItem("custom1", new SelectionHandler<MenuItem>() {
            @Override
            public void onSelection(SelectionEvent<MenuItem> event) {
                Info.display("test", "You clicked custom1");
            }
        }));
        return menu;
    }
});

I would like to work by column name and not by colIndex because the order of the column can change during runtime.我想按列名而不是 colIndex 工作,因为列的顺序可以在运行时改变。 How can I get the name of the column?如何获取列的名称? And what is best practice.什么是最佳实践。

Thank you.谢谢你。

I do not think that you can search for columns in a grid using a name String.我不认为您可以使用名称字符串搜索网格中的列。 But, you can search for a column using the path:但是,您可以使用以下路径搜索列:

grid.getColumnModel().findColumnConfig("myValueProviderPath");

where "myValueProviderPath" is the value provider path.其中“myValueProviderPath”是值提供者路径。 This will retun a matching column or null if no match.如果不匹配,这将重新调整匹配列或 null。

I did it like this:我是这样做的:

mGrid.setView(createContextMenu(colIndex) --> {
    Menu m = super.createContextMenu(colIndex);
    ColumnConfig cfg = mGrid.getColumnModel().getColumn(colIndex);
    if (cfg.getCellClassName().equals("mycolumn")) {
       // add additional menu item
    }
    return m;
}

of course you need to fill cellClassName with a column name before.当然,您之前需要用列名填充 cellClassName 。

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

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