【问题标题】:Checking for existing value in Grid Panel in ExtJS在 ExtJS 的网格面板中检查现有值
【发布时间】:2012-01-28 04:05:28
【问题描述】:

如果我在 ExtJS 4 中有一个网格面板,我该如何检查其中的值?

我正在构建一个弹出窗口以向网格面板添加值,并且我想确保用户尝试添加到网格面板的值尚未在网格面板中列出。

我已经搜索了一段时间的文档并在谷歌上搜索并没有找到任何东西。

【问题讨论】:

    标签: extjs extjs4


    【解决方案1】:

    我在http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/grid/array-grid.html的示例底部添加了以下代码

    希望这对您来说是一个开始,尽管您可能需要考虑以下其他事项,以便设计出最强大的解决方案:

    • 如果同一值可以在网格中出现多次怎么办?
    • 如果网格中的数据分页了怎么办?

    代码:

    dockedItems: [{
            xtype: 'toolbar',
            items : [ {
                xtype: 'button',
                text: 'Seek Value',
                handler: function() {
            Ext.Msg.prompt('Value in Grid?', 'Search:', function(btn, text){
                    if (btn == 'ok' && text){
                        var columnNames = Ext.Array.pluck(grid.columns, 'dataIndex');
    
                        grid.store.data.each(function(record, index) {
                            for (var i=0,n=columnNames.length; i<n; i++) {
                                var columnName = columnNames[i];
    
                                if (columnName) { //protects against null dataIndex using pluck above
                                    if (record.get(columnName) == text) {
                                        console.log(index); //row
                                        console.log(columnName);
                                        return;
                                    }
                                }
                            }
                        });
                    }
            });
                }
            }],
            dock: 'bottom'
        }]
    

    【讨论】:

    • 谢谢,这绝对是一个好的开始,也是值得考虑的好点。我真的很惊讶这不是内置在网格面板中。我想会有一些我可以调用的方法,或者它甚至可以在将东西插入商店时自动检查。
    猜你喜欢
    • 1970-01-01
    • 2011-02-15
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多