ExtJS 仅根据条件显示 RowExpander

发布于 2025-01-02 09:33:32 字数 1274 浏览 3 评论 0原文

我目前有一个相当大的网格,并且成功地使用 RowExpander 插件来显示某些行的补充信息。我的问题是,并非所有行都包含上述补充信息,并且我不希望 RowExpander 处于活动状态,也不希望在特定数据存储的条目为空时显示它的“+”图标。我尝试在 RowExpander 对象上使用传统的“渲染器”属性,但它不起作用。

所以基本上,如何才能仅在某个数据存储的字段 != "" 时才显示并激活 RowExpander 的图标和双击?

提前致谢! =)

编辑:我找到了一个解决方案

正如 e-zinc 所说,解决方案的一部分(至少对我来说)是提供一个自定义渲染器来检查我的条件字段。这是我的 RowExpander:

this.rowExpander = new Ext.ux.grid.RowExpander({
    tpl: ...
    renderer: function(v, p, record) {
                if (record.get('listeRetourChaqueJour') != "") {
                    p.cellAttr = 'rowspan="2"';
                    return '<div class="x-grid3-row-expander"></div>';
                } else {
                    p.id = '';
                    return '&#160;';
                }
    },
    expandOnEnter: false,
    expandOnDblClick: false
});

现在,这里的技巧是,对于这个特定的网格,我选择不允许 ExpandOnEnter 和 expanOnDblClick 因为 RowExpander 有时不会被渲染。此外,包含“+”图标的网格单元的 CSS 类是“x-grid3-td-expander”。这是由于 CSS 类自动设置为 x-grid3-td-[id-of-column] 造成的。因此,通过仅在不渲染 rowExpander 时将 id 设置为 '',我还删除了未渲染单元格的灰色背景。所以,没有双击,没有输入,没有图标,没有灰色背景。对于我的数据存储字段为空的列(当我不需要 RowExpander 时),它真的变得好像严格不涉及 RowExpander。

这对我来说很有效。对于那些希望保留单元格 ID 或希望保持双击并输入事件正常工作的人来说,我想除了扩展类之外别无他法。希望这可以帮助其他陷入我困境的人!

I currently have a rather big Grid and am successfully using the RowExpander plugin to display complementary informations on certain rows. My problem is that it's not all rows that contain the aforementioned complementary informations and I do not wish the RowExpander to be active nor to show it's "+" icon if a particular data store's entry is empty. I tried using the conventional "renderer" property on the RowExpander object, but it did not work.

So basically, how can you have the RowExpander's icon and double click shown and activated only if a certain data store's field != ""?

Thanks in advance! =)

EDIT: I found a solution

As e-zinc stated it, part of the solution (for me at least) was to provide a custom renderer that would check my conditional field. Here is my RowExpander:

this.rowExpander = new Ext.ux.grid.RowExpander({
    tpl: ...
    renderer: function(v, p, record) {
                if (record.get('listeRetourChaqueJour') != "") {
                    p.cellAttr = 'rowspan="2"';
                    return '<div class="x-grid3-row-expander"></div>';
                } else {
                    p.id = '';
                    return ' ';
                }
    },
    expandOnEnter: false,
    expandOnDblClick: false
});

Now, the trick here is that for this particular Grid, I chose not to allow the expandOnEnter and expanOnDblClick since the RowExpander will sometimes not be rendered. Also, the CSS class of the grid cell that will hold the "+" icon is 'x-grid3-td-expander'. This is caused by the fact that the CSS class is automatically set to x-grid3-td-[id-of-column]. So, by setting the id to '' only when I'm not rendering the rowExpander, I'm also removing the gray background of the un-rendered cells. So, no double click, no enter, no icon, no gray-background. It really becomes as if there is strictly no RowExpander involved for the columns where my data store field is empty (when I want no RowExpander).

That did the trick for me. For someone that wishes to preserve the ID of the cell, or that wishes to keep the double click and enter events working, there is nothing else to do other than extending the class I guess. Hope this can help other people stuck in the position I was!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏有森光若流苏 2025-01-09 09:33:32

正如 e-zinc 所说,解决方案的一部分(至少对我来说)是提供一个自定义渲染器来检查我的条件字段。这是我的 RowExpander:

this.rowExpander = new Ext.ux.grid.RowExpander({
    tpl: ...
    renderer: function(v, p, record) {
                if (record.get('listeRetourChaqueJour') != "") {
                    p.cellAttr = 'rowspan="2"';
                    return '<div class="x-grid3-row-expander"></div>';
                } else {
                    p.id = '';
                    return ' ';
                }
    },
    expandOnEnter: false,
    expandOnDblClick: false
});

现在,这里的技巧是,对于这个特定的 Grid,我选择不允许专门使用 ExpandOnEnter 和 ExpandOnDblClick,因为 RowExpander 有时不会被渲染。此外,包含“+”图标的网格单元的 CSS 类是“x-grid3-td-expander”。这是由于 CSS 类自动设置为 x-grid3-td-[id-of-column] 造成的。因此,通过仅在不渲染 rowExpander 时将 id 设置为空字符串,我还删除了不提供任何扩展的单元格的灰色背景。所以,没有双击,没有输入,没有图标,没有灰色背景。对于我的数据存储字段为空的列(当我不需要 RowExpander 时),它真的变得好像严格不涉及 RowExpander。

这对我来说很有效。对于希望保留单元格 ID 或希望保持双击和输入事件正常工作的人来说,在我看来,除了扩展 RowExpander 类之外,别无他法。当然,也可以使用 Ext.override(),但是 RowExpander 的所有实例都会受到覆盖的影响。

As e-zinc stated it, part of the solution (for me at least) was to provide a custom renderer that would check my conditional field. Here is my RowExpander:

this.rowExpander = new Ext.ux.grid.RowExpander({
    tpl: ...
    renderer: function(v, p, record) {
                if (record.get('listeRetourChaqueJour') != "") {
                    p.cellAttr = 'rowspan="2"';
                    return '<div class="x-grid3-row-expander"></div>';
                } else {
                    p.id = '';
                    return ' ';
                }
    },
    expandOnEnter: false,
    expandOnDblClick: false
});

Now, the trick here is that for this particular Grid, I chose not to allow the expandOnEnter and expandOnDblClick specifically since the RowExpander will sometimes not be rendered. Also, the CSS class of the grid cell that will hold the "+" icon is 'x-grid3-td-expander'. This is caused by the fact that the CSS class is automatically set to x-grid3-td-[id-of-column]. So, by setting the id to an empty string only when I'm not rendering the rowExpander, I'm also removing the gray background of the cells that won't offer any expanding. So, no double click, no enter, no icon, no gray-background. It really becomes as if there is strictly no RowExpander involved for the columns where my data store field is empty (when I want no RowExpander).

That did the trick for me. For someone that wishes to preserve the ID of the cell, or that wishes to keep the double click and enter events working, there is nothing else to do other than extending the RowExpander class in my opinion. Of course, one could also use Ext.override(), but then all instances of RowExpander would be hit by the override.

月野兔 2025-01-09 09:33:32

我有同样的任务,我有一个解决方案

var rowExpander = new Ext.ux.grid.RowExpander({
    renderer : function(v, p, record){
       return record.get('relatedPageCount') > 0 ? '<div class="x-grid3-row-expander"> </div>' : ' ';
    }
});

,我重写了 render 方法,该方法测试存储中的 relatedPageCount 字段并渲染 + 或空白。

I have the same task, there is my solution

var rowExpander = new Ext.ux.grid.RowExpander({
    renderer : function(v, p, record){
       return record.get('relatedPageCount') > 0 ? '<div class="x-grid3-row-expander"> </div>' : ' ';
    }
});

I have overridden render method which test relatedPageCount field in store and render + or white space.

吾性傲以野 2025-01-09 09:33:32

我想我找到了一个更干净的解决方案。请给我反馈:)
我扩展了 RowExpander 的toggleRow 方法,如果我匹配条件,则避免切换行。否则标准流程将继续

Ext.create('customplugins.grid.plugin.ClickRowExpander',{
        pluginId : 'rowexpander',
        rowBodyTpl : new Ext.XTemplate(
                '<p><b>Last Modified By:</b> {usermodify}</p>',
                '<p><b>User data:</b> {userdata}</p>',
                '<p><b>Correlation ID:</b> {correlationid}</p>',
                '<p><b>Description:</b> {descr}</p>'
        ),
        toggleRow : function(rowIdx, record) {
            if(record.get('directory')) return false;
            customplugins.grid.plugin.ClickRowExpander.prototype.toggleRow.apply(this, arguments);
        }

    })

I think I've found a cleaner solution.Give me a feedback pls :)
I extend the toggleRow method of RowExpander and if I match a condition avoid to toggle the row.Otherwise the standard flow continues

Ext.create('customplugins.grid.plugin.ClickRowExpander',{
        pluginId : 'rowexpander',
        rowBodyTpl : new Ext.XTemplate(
                '<p><b>Last Modified By:</b> {usermodify}</p>',
                '<p><b>User data:</b> {userdata}</p>',
                '<p><b>Correlation ID:</b> {correlationid}</p>',
                '<p><b>Description:</b> {descr}</p>'
        ),
        toggleRow : function(rowIdx, record) {
            if(record.get('directory')) return false;
            customplugins.grid.plugin.ClickRowExpander.prototype.toggleRow.apply(this, arguments);
        }

    })
明月松间行 2025-01-09 09:33:32

此版本适用于 Ext JS 5 和 6(经典)

有一件事是删除 +/ - 图标,可以通过网格 viewConfig 完成:

getRowClass: function (record, rowIndex, rowParams, store) {
var yourFieldofChoice = record.get('yourFieldofChoice');
if (yourFieldofChoice == null) {
返回“隐藏行扩展器”;
}
},

为 hide-row-expander 定义 css:

.hide-row-expander .x-grid-row-expander {
可见性:隐藏;
现在,

您可以通过覆盖toggleRow来禁用回车键上的扩展(Ext JS 6中不再支持'expandOnEnter'配置)或双击,或者如果您不希望覆盖,您可以创建基于现有插件构建的自定义rowexpander :

Ext.define('RowExpander', {
扩展:'Ext.grid.plugin.RowExpander',
别名: 'plugin.myExpander',
初始化:函数(网格){
var我=这个;
me.grid = 网格;
me.callParent(参数);
},
requiredFields: ['您的选择字段'],
hasRequiredFields: 函数 (rec) {
var 有效=假;
Ext.each(this.requiredFields, 函数(字段) {
if (!Ext.isEmpty(rec.get(field))) {
有效=真;
}
});
返回有效;
},
切换行:函数(rowIdx,记录){
var me = 这个,rec;
rec = Ext.isNumeric(rowIdx)? me.view.getStore().getAt(rowIdx) : me.view.getRecord(rowIdx);
if (me.hasRequiredFields(rec)) {
me.callParent(参数);
}
}
});

This version works in Ext JS 5 and 6 (classic)

One thing is to remove the +/- icon, which can be done via grid viewConfig:

getRowClass: function (record, rowIndex, rowParams, store) {
var yourFieldofChoice = record.get('yourFieldofChoice');
if (yourFieldofChoice == null) {
return 'hide-row-expander';
}
},

Define css for hide-row-expander:

.hide-row-expander .x-grid-row-expander {
visibility: hidden;
}

Now you disable expanding on enter key ('expandOnEnter' config is no longer supported in Ext JS 6) or double click by overriding toggleRow, or if you do not wish the override you create your custom rowexpander built on existing plugin:

Ext.define('RowExpander', {
extend: 'Ext.grid.plugin.RowExpander',
alias: 'plugin.myExpander',
init: function (grid) {
var me = this;
me.grid = grid;
me.callParent(arguments);
},
requiredFields: ['yourFieldofChoice'],
hasRequiredFields: function (rec) {
var valid = false;
Ext.each(this.requiredFields, function (field) {
if (!Ext.isEmpty(rec.get(field))) {
valid = true;
}
});
return valid;
},
toggleRow: function (rowIdx, record) {
var me = this, rec;
rec = Ext.isNumeric(rowIdx)? me.view.getStore().getAt(rowIdx) : me.view.getRecord(rowIdx);
if (me.hasRequiredFields(rec)) {
me.callParent(arguments);
}
}
});

手心的海 2025-01-09 09:33:32

我已经在 Ext.ux.grid.RowExpander 的侦听器中处理了 beforeexpand 事件。 beforeexpand 方法注入了整行数据。有条件地检查数据,我们可以返回 true 或 false。如果我们返回 false 它就不会扩展,否则它就会扩展。

var expander = new Ext.ux.grid.RowExpander({
            tpl: '<div class="ux-row-expander"></div>',

            listeners: {

                beforeexpand : function(expander, record, body, rowIndex){

                    var gpdata = record.data.GROUP_VALUES[1].COLUMN_VALUE
                    if(gpdata == null){
                        return false;
                    }
                    else{
                        return true;
                    }
                }
            }
        });

I have handled the beforeexpand event inside the listeners of Ext.ux.grid.RowExpander. beforeexpand method got the whole row data injected. Checking the data conditionally we can return true or false. If we return false it wont expand otherwise it will do.

var expander = new Ext.ux.grid.RowExpander({
            tpl: '<div class="ux-row-expander"></div>',

            listeners: {

                beforeexpand : function(expander, record, body, rowIndex){

                    var gpdata = record.data.GROUP_VALUES[1].COLUMN_VALUE
                    if(gpdata == null){
                        return false;
                    }
                    else{
                        return true;
                    }
                }
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文