Extjs分页网格不是从没有存储的第一页过滤,loadPage(1)

时间:2015-02-05 06:22:46

标签: extjs

我正在使用ExtJs 4版本,我创建了客户端分页。当我在第二页中搜索网格时,它不是从网格的第一页搜索商店。这是view.js

{
    xtype: 'textfield',
    id: 'detailsSearchBox',
    selectOnFocus: true,
    margin:'0 0 0 10',
    mode: 'remote',
    listeners: {
            change :function(field, newValue, oldValue, options){
                    Store.clearFilter(true);
                    var grid = Ext.getCmp('Grid');
                    var total = localStorage.getItem('total');
                    var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");
                                                console.log('grid.store.getCurrentPage ', grid.store.currentPage);
                                                var tb = Ext.getCmp('pagingtool');
                    console.log('window.data ', window.data);
                    records = [];
                    Ext.each(tempClusterData, function(record) {
                    for (var i = 0; i < grid.columns.length; i++) {
                            if (grid.omitColumns) {
                                    if (grid.omitColumns.indexOf(grid.columns[i].dataIndex) === -1) {
                                            if (matcher.test(record[grid.columns[i].dataIndex]){
                                                if (!grid.filterHidden && grid.columns[i].isHidden()) {
                                                        continue;
                                                } else {
                                                    records.push(record);
                                                        break;
                                                };
                                            };
                                    };
                                } else {
                                                            if (matcher.test(record[grid.columns[i].dataIndex]) {
                                                                //console.log('else - if**** ', record[grid.columns[i].dataIndex],  matcher);
                                                                if (!grid.filterHidden && grid.columns[i].isHidden()) {
                                                                    continue;
                                                                } else {
                                                            records.push(record);
                                                                    window.data= records;
                                                                    break;
                                                                };
                                                            };
                                                        };
                                                    }  
                                                });
                                                data = window.data;
                                                data.length=window.data.length;

                                                 grid.store.load({ params: { query: matcher, start: 0, limit: window.total } });
                                            },

                                        }
                                    }     

我的store.js是

var fetchedData = function(){
this.data = null;
this.total = 0;
}

var data = JSON.parse(localStorage.getItem('data')); 
var total = localStorage.getItem('total');

function createPagination(page, count) {

    var tmp = [];
    var startIndex = (page * count) - count;
    if(startIndex <= data.length-1)
    {
        var endIndex = startIndex + (count -1);
        if(endIndex > data.length -1)
            endIndex = data.length -1;
        for(;startIndex <= endIndex;startIndex++)
        {
            tmp.push([data[startIndex].Id, data[startIndex].Name,    data[startIndex].start, data[startIndex].end, data[startIndex].status,  data[startIndex].year);
        }
    }
    return data;
}
var store = Ext.define('EMS.store.store', {
extend: 'Ext.data.Store',
alias: 'store.ctore',
model: 'EMS.model.cModel',
requires: [
    'EMS.model.cModel'
],
//autoLoad: true,
pageSize : 3,
proxy: {
        type: 'memory',
        reader: {
            type: 'array',
            root: 'data', 
            totalProperty : 'total'
        }
},
listeners : {
        beforeload : function(store, operation, eOpts){
            var page = operation.page;
            var limit = operation.limit;  
            fetchedData.data = createPagination(page, limit);
            fetchedData.total = total;
            store.proxy.data = fetchedData;
        }
}

}); 

2 个答案:

答案 0 :(得分:0)

我发现我的问题的原因是代码我在for循环中有所改变。只需在else块中看到注释行。

records = [];
Ext.each(cData, function(record) {
 for (var i = 0; i < grid.columns.length; i++) {
    if (grid.omitColumns) {
        if (grid.omitColumns.indexOf(grid.columns[i].dataIndex) === -1) { 
            if (matcher.test(record[grid.columns[i].dataIndex]){ 
                if (!grid.filterHidden && grid.columns[i].isHidden()) {
                    continue;
                } else {
                    records.push(record);
                    break;

                };
            };
        };
    } else {
        if (matcher.test(record[grid.columns[i].dataIndex]){  
            if (!grid.filterHidden && grid.columns[i].isHidden()) { 
                continue;
            } else {
                records.push(record);
                break;
            };
            }else{
                window.data.pop();  // I have added this line so it is  working now 
            }
    };
}  
});
window.data= records;
window.data.length= records.length;
grid.store.load({ params: {start: 0, limit: window.total } }); 

答案 1 :(得分:0)

如果要根据商店中可用的匹配记录数更改分页工具栏显示消息。

records = [];
var pbt = Ext.getCmp('pagingtoolbar');
Ext.each(cData, function(record) {
for (var i = 0; i < grid.columns.length; i++) {
    if (grid.omitColumns) {
        if (grid.omitColumns.indexOf(grid.columns[i].dataIndex) === -1) { 
            if (matcher.test(record[grid.columns[i].dataIndex]){ 
                if (!grid.filterHidden && grid.columns[i].isHidden()) {
                    continue;
                } else {
                    records.push(record);
                    break;

                };
            };
        };
    } else {
        if (matcher.test(record[grid.columns[i].dataIndex]){  
            if (!grid.filterHidden && grid.columns[i].isHidden()) { 
                continue;
            } else {
                records.push(record);
                    if(records .length < 3){
                        window.total =  records .length;
                        pbt.child('#first').hide();
                        pbt.child('#prev').hide();
                        pbt.child('#next').hide();
                        pbt.child('#last').hide();
                        pbt.child('#afterTextItem').hide();
                        pbt.child('#inputItem').hide();
                    }else{
                        window.total =  records .length;
                        pbt.child('#first').show();
                        pbt.child('#prev').show();
                        pbt.child('#next').show();
                        pbt.child('#last').show();
                        pbt.child('#afterTextItem').show();
                        pbt.child('#inputItem').show();
                    }
                break;
            };
            }else{
                window.data.pop();  // I have added this line so it is working now  
            }
    };
}  
});
window.data= records;
window.data.length= records.length;
grid.store.load({ params: {start: 0, limit: window.total } });