Extjs4如何从网格中删除重复的行?

问题描述 投票:1回答:2

My_grid包含许多重复的行(相同的nameusername,并且具有不同的隐藏的id)。如何删除重复的行?

grid extjs4 filtering
2个回答
3
投票

您应该在代理的阅读器上或在模型上设置idProperty

var myStore = Ext.create('Ext.data.Store', {
    proxy: {
        type: 'ajax',
        url: '/myUrl',
        reader: {
            idProperty: 'Id'
        }
    },
    model: 'myModel'
});

1
投票

此片段希望对您有用:

重要的是,您要以此声明商店和网格。例如this.store = ...

  //Listener on the button removes the duplicated rows
        this.button.on('click', function() {
            this.store.each(function(record) {
                //This is necessary because if this record was removed before
                if(record !== undefined) {
                    //Find all records which have the same name like this record
                    var records = record.store.query('name', record.get('name'));

                    //Remove all found records expect the first record 
                    records = records.each(function(item, index) {
                        //Don't delete the first record
                        if(index != 0) {
                            item.store.remove(item);    
                        }    
                    });    
                }
            }); 
        }, this);
© www.soinside.com 2019 - 2024. All rights reserved.