【问题标题】:Grid loses (visible) selection after store-record edit and after commit存储记录编辑和提交后网格丢失(可见)选择
【发布时间】:2012-10-04 13:33:24
【问题描述】:

我有一个简单的案例,我有一个带有附加商店的网格。

有 2 个按钮。一个带有修改所选记录的处理程序。一个带有提交所选记录的处理程序。

当我选择一条记录并推送编辑 -> 编辑发生选择(看起来丢失)如果你打电话给grid.geSelectionModel().getSelection() 你会看到该记录仍然被选中。它只是没有那样显示。

你不能再选择它,你必须先选择另一个记录,然后再选择记录。

其次,当您选择一条记录单击提交按钮时,该值被提交,但选择再次“显示”为丢失。

这是一个错误吗?我怎样才能解决这个问题?我希望它保持选择可见!

Here is a fiddle

这里是示例代码:(我使用 Ext 4.1.1)

var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
        clicksToEdit: 1
    });

Ext.create('Ext.data.Store', {
    storeId: 'simpsonsStore',
    fields: ['name', 'email', 'phone'],
    data: {
        'items': [{
            'name': 'Lisa',
            "email": "lisa@simpsons.com",
            "phone": "555-111-1224"
        }, {
            'name': 'Bart',
            "email": "bart@simpsons.com",
            "phone": "555-222-1234"
        }, {
            'name': 'Homer',
            "email": "home@simpsons.com",
            "phone": "555-222-1244"
        }, {
            'name': 'Marge',
            "email": "marge@simpsons.com",
            "phone": "555-222-1254"
        }]
    },
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

Ext.create('Ext.container.Container', {
    layout: 'fit',
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'grid',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [{
            text: 'Name',
            dataIndex: 'name'
        }, {
            text: 'Email',
            dataIndex: 'email',
            flex: 1
        }, {
            text: 'Phone',
            dataIndex: 'phone'
        }],
        height: 200,
        buttons: [{
            text: 'commit selection',
            handler: function(){
                this.up('grid').getSelectionModel().getSelection()[0].commit();
            }
        },{
            text: 'set selection name to maggy',
            handler: function(){
                this.up('grid').getSelectionModel().getSelection()[0].set('name', 'Maggy');
            }
        }]
    }]
});​

更新:

我在sencha forum 上报告了它。 Mitchel Simoens 告诉我它已在 Ext 4.1.2 中修复。太糟糕了,它是“仅限支持订阅者”版本..

更新:

我正在查找问题并尝试修复它。我相信问题出在 onUpdate 方法中的 Ext.view.Table 类中,更准确地说是围绕这段代码:

if (oldRowDom.mergeAttributes) {
    oldRowDom.mergeAttributes(newRow, true);
} else {
    newAttrs = newRow.attributes;
    attLen = newAttrs.length;
    for (i = 0; i < attLen; i++) {
        attName = newAttrs[i].name;
        if (attName !== 'id') {
           oldRowDom.setAttribute(attName, newAttrs[i].value);
        }
    }
}

只留下这段代码是不是一个坏主意?我评论了它似乎现在可以工作了,但它不会破坏其他一些功能吗? http://jsfiddle.net/Vandeplas/YZqch/10/

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    我认为这是一个错误,可能是刷新网格以显示脏位的一部分。
    我以一种丑陋的方式规避了这一点,in your revised fiddle:

    {
        text: 'set selection name to maggy',
        handler: function(){
            var sel = this.up('grid').getSelectionModel();
            var rec = sel.getSelection()[0];
            rec.set('name', 'Maggy');
            sel.deselectAll();
            sel.select(rec.index);
        }
    }
    

    我为.set() 做了这个,但同样可以为commit()

    希望这会有所帮助。

    【讨论】:

    • 这是最明显的解决方案。但这会触发选择事件。我发布了一个非常简化的示例。但在我的真实应用程序中,我会监听选择事件以加载其他面板。在面板中我进行了修改,poef selection 消失并保存,poef selection 又消失了。
    • improved 它通过暂停事件来解决。这种解决方案是否适用于分页商店? rec.index 总是正确的吗?
    • 关于分页的建议我是最后一个,因为我什至无法让无限滚动为我们工作。我相信rec.index 将是正确的,只要您在处理程序中的同一功能期间不刷新网格。但如果你这样做,你甚至想要选择同一行吗?归根结底,我讨厌我们的两种方法,因为它们是丑陋的黑客,否则简单的功能不起作用。 BL2:你的代码非常好。
    • 在我发现当前应用程序中存在同样问题之前,我偶然发现了这篇文章,修复效果很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多