ExtJS4.2 Grid Filter Leaves empty Rows with Paging

2019-09-01 04:31发布

I have tried various ways to refresh the grid but everything I try doesn't work. Do I refresh the Grid or do I load the store??? You can see that the paging tool bar is still showing 50 pages after the filtering. If there are no dates on a given pag and it is empty then it will disable the tool bar and paging doesn't work after that page un less you refresh the browser and skip over the empty page. So, in my case page 15 has no rows so it breaks when u hit next and get that page. If you type in the page number 16 then all is good until you hit another's empty page. My datepicker is in my viewport below and I have tried refreshing the gird and loading the store as well as other things which mostly result in undefined error. Not sure where to start with this one so I will show my code and screen shots below:

BEFORE DATE SELECTION:

enter image description here

AFTER DATE SELECTION:

enter image description here

STORE:

Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',
autoLoad: true,
autoSync:true,
pageSize:50,
proxy:
{
    type: 'ajax',

     //extraParams :{limit:1000},

    api:
    {
        read: 'http://192.168.0.103/testit/dao_2.cfc?method=getContent',
        update: 'http://192.168.0.103/testit/dao_2-post.cfc?method=postContent'
    },
    reader:
    {
        type: 'json',
        root: 'data',
        successProperty: 'success',
        totalProperty : 'dataset',
        remoteFilter : true
    },
    listeners:
    {
        // stuff goes here maybe??

    }
}   
});

GRID PANEL:

Ext.define('AM.view.user.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: 'All Users',
store: 'Users',
//buffered: true,
plugins:[Ext.create('Ext.grid.plugin.RowEditing', {clicksToEdit: 2})],
dockedItems: [{ xtype: 'pagingtoolbar',
                store: 'Users',
                dock: 'bottom',
                displayMsg: 'Displaying Records {0} - {1} of {2}',
                displayInfo: true}],


initComponent: function() {

    this.columns = [
                    Ext.create('Ext.grid.RowNumberer',
                        {
                        resizable: true,
                        resizeHandles:'all',
                        align: 'center',
                        minWidth: 35,
                        maxWidth:50
                        }),
                    {
                    header: 'Name',
                    dataIndex: 'message_id',
                    flex: 1,
                    editor:'textfield',
                    allowBlank: false,
                    menuDisabled:true
                    },
                    {
                    header: 'Email',
                    dataIndex: 'recip_email',
                    flex: 1,
                    editor:'textfield',
                    allowBlank: false,
                    menuDisabled:true
                    },
                    {
                    header: 'Date Time',
                    dataIndex: 'unix_time_stamp',
                    width: 120,
                    menuDisabled:true,
                    // submitFormat: 'd/m/Y',
                    renderer: Ext.util.Format.dateRenderer('m/d/Y'),
                    field:{ xtype:'datefield',
                            autoSync:true,
                            allowBlank:false,
                            editor: new Ext.form.DateField(
                                    {format: 'm/d/y'})  }
                    }];


    this.callParent(arguments);

},

});

VIEWPORT:

Ext.Loader.setConfig({enabled:true});

Ext.application({
requires: ['Ext.container.Viewport'],
name: 'AM',
appFolder: 'app',
controllers: ['Users'],

launch: function() {

    Ext.create('Ext.container.Viewport', {
    layout: 'border',
    items:[{
            region: 'center',
            itemId:'centerPanelRegion',
            title:'The Title',
            xtype: 'tabpanel',
            hidden: true,
            activeTab: 0,
            items:[{
                    xtype: 'userlist',
                    listeners:
                    {
                        select: function(selModel, record, index, options)
                        {
                            // do something with the selected date
                            console.log('select');
                        },
                        add: function(selModel)
                        {
                            // do something with the selected date
                            console.log('add - init2.js');
                        },
                        afterrender:function(selModel)
                        {
                            // do something with the selected date
                            console.log('afterrender - userlist(init2.js)');
                        },
                        beforerender:function(selModel)
                        {
                            // do something with the selected date
                            console.log('beforerender - userlist(init2.js)');
                        }
                    }
                  }]
            },
            {
            region: 'west',
            itemId:'westPanelRegion',
            hidden: true,
            layout:'fit',
            xtype: 'tabpanel',
            activetab:0,
            collapsible:false,
            split: false,
            title: 'The Title',
            width:178,
            maxWidth:400,
            height: 100,
            minHeight: 100,
            items:[{
                    title: 'Tab 1',
                    xtype:'panel',
                    items:
                        [{
                        xtype: 'datepicker',
                        itemId:'datePickerFld',
                        listeners:{
                            beforerender: function(){
                                console.log('datepicker - beforerender(init2.js)');
                                var store = Ext.getStore('dates');
                                store.load({callback: function(){
                                console.log('datepicker - callback(init2.js');
                                console.log(store.data.items[999].data.recip_email);
                                console.log(store.data.items[999].data.unix_time_stamp);
                                }
                                })
                            }
                        },

                        handler: function(picker, date)
                            {
                            // do something with the selected date
                            console.log('date picker example in init2.js' + Ext.Date.format(date,'m/d/Y'));

                            // get store by unique storeId
                            var store = Ext.getStore('Users');

                            // clear current filters
                             store.clearFilter(true);

                            // filter store
                            Ext.encode(store.filter("unix_time_stamp", Ext.Date.format(date,'m/d/Y')));

                            //store.load();
                            //store.sync();

                            }
                        }]
            },
            {
                title: 'Tab 2',
                html: 'ers may be added dynamically  - Others may be added dynamically',
            }]

         }]
    });
}
});

CONTROLLER:

Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
stores:['Users', 'dates'],
models:['User', 'date'],
views: ['user.List','user.Edit'],


init: function() {

    Ext.getStore('dates').addListener('load',this.ondatesStoreLoad, this);

    this.control(
    {

        'viewport > userlist':
        {
            itemdblclick: this.editUser,
        },

        'useredit button[action=save]':
        {
            click: this.updateUser
        }           

    });

},


// ----------  handler Function declarations  -------------

ondatesStoreLoad: function(me,records,success)
{

// ------  Gets the dates from dates store and loads an array
var store = this.getStore('dates');
sendDataArray = [];

store.each(function(record){
    var recordArray = [record.get("unix_time_stamp")];
    sendDataArray.push(recordArray);
});         


// ------  Set DatePicker Bullshit right fucking here  --------//

var dtFld = Ext.ComponentQuery.query('#datePickerFld')[0];

dtFld.setDisabledDates(["^(?!"+sendDataArray.join("|")+").*$"]);
dtFld.setMaxDate(new Date());
dtFld.setMinDate(new Date('05/01/2013'));


var wstPnlReg = Ext.ComponentQuery.query('#westPanelRegion')[0];
wstPnlReg.show();

var ctrPnlReg = Ext.ComponentQuery.query('#centerPanelRegion')[0];
ctrPnlReg.show();

// var grid = Ext.widget('userlist');

},

onUsersStoreDataChange: function(me)
{
    //console.log('Hey the store data just changed!');
},

editUser: function(grid, record)
{
    var view = Ext.widget('useredit');
    view.down('form').loadRecord(record);
},

updateUser: function(button)
{
    var win    = button.up('window'),
        form   = win.down('form'),
        record = form.getRecord(),
        values = form.getValues();

    record.set(values);
    win.close();
    this.getUsersStore().sync();
},

});

UPDATED VIEWPORT: Changes made only in datepicker handler

Ext.Loader.setConfig({enabled:true});

Ext.application({
requires: ['Ext.container.Viewport'],
name: 'AM',
appFolder: 'app',
controllers: ['Users'],

launch: function() {

    Ext.create('Ext.container.Viewport', {
    layout: 'border',
    items:[{
            region: 'center',
            itemId:'centerPanelRegion',
            title:'The Title',
            xtype: 'tabpanel',
            hidden: true,
            activeTab: 0,
            items:[{
                    xtype: 'userlist',
                    listeners:
                    {
                        select: function(selModel, record, index, options)
                        {
                            // do something with the selected date
                            console.log('select');
                        },
                        add: function(selModel)
                        {
                            // do something with the selected date
                            console.log('add - init2.js');
                        },
                        afterrender:function(selModel)
                        {
                            // do something with the selected date
                            console.log('afterrender - userlist(init2.js)');
                        },
                        beforerender:function(selModel)
                        {
                            // do something with the selected date
                            console.log('beforerender - userlist(init2.js)');
                        }
                    }
                  }]
            },
            {
            region: 'west',
            itemId:'westPanelRegion',
            hidden: true,
            layout:'fit',
            xtype: 'tabpanel',
            activetab:0,
            collapsible:false,
            split: false,
            title: 'The Title',
            width:178,
            maxWidth:400,
            height: 100,
            minHeight: 100,
            items:[{
                    title: 'Tab 1',
                    xtype:'panel',
                    items:
                        [{
                        xtype: 'datepicker',
                        itemId:'datePickerFld',
                        listeners:{
                            beforerender: function(){
                                console.log('datepicker - beforerender(init2.js)');
                                var store = Ext.getStore('dates');
                                store.load({callback: function(){
                                console.log('datepicker - callback(init2.js');
                                console.log(store.data.items[999].data.recip_email);
                                console.log(store.data.items[999].data.unix_time_stamp);
                                }
                                })
                            }
                        },

                        handler: function(picker, date)
                            {
                                // do something with the selected date
                        console.log('date picker example in init2.js' + Ext.Date.format(date,'m/d/Y'));

                        // get store by unique storeId
                            var store = Ext.getStore('Users');

                            // clear current filters
                             store.clearFilter(true);

                            // filter store
                            store.filter("unix_time_stamp", Ext.Date.format(date,'m/d/Y'));

                        // Load the store
                        store.load();


                            }
                        }]
            },
            {
                title: 'Tab 2',
                html: 'ers may be added dynamically  - Others may be added dynamically',
            }]

         }]
    });
}
});

1条回答
Fickle 薄情
2楼-- · 2019-09-01 04:37

This line is likely causing the issues.

Ext.encode(store.filter("unix_time_stamp", Ext.Date.format(date,'m/d/Y')));

I'm not sure why you are calling Ext.encode on whatever store.filter returns, but I don't think you want to do that (and it is likely causing the undefined errors).

As for the paging toolbar not updating the current count, it is likely you just aren't returning the correct information in your server response when updating the store. The server response should include the total number of records. According to the docs for Ext.toolbar.Paging, http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.toolbar.Paging:

The packet sent back from the server would have this form:

{
    "success": true,
    "results": 2000,
    "rows": [ // ***Note:** this must be an Array
        { "id":  1, "name": "Bill", "occupation": "Gardener" },
        { "id":  2, "name":  "Ben", "occupation": "Horticulturalist" },
        ...
        { "id": 25, "name":  "Sue", "occupation": "Botanist" }
    ]
}
查看更多
登录 后发表回答