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

时间:2013-02-26 12:48:10

标签: grid extjs4 filtering

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

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分: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);