sencha list paging plugin

前端 未结 5 1570
渐次进展
渐次进展 2021-02-10 06:38

I\'m trying to use sencha touch\'s listpaging plugin. But there is almost no good( or bad ) documentation about how to use it and i\'m confused.

When i activate the plu

相关标签:
5条回答
  • 2021-02-10 07:07

    I'm having problems finding good documentation, too, but I can at least answer your question. You need to add pageSize to your store, clearOnPageLoad as well, if you want to not clear out what was already loaded. Her's my code:

    Ext.regStore('publicresources', {
    
    model: 'PublicResource',
    autoLoad:false,
    remoteFilter:true,
    sortOnFilter:true,
        pageSize: 15,
        clearOnPageLoad: false, 
    sorters: [
        {
            property : 'distance',
            direction: 'ASC'
        }
    ]
    

    });

    My outstanding issues that I'm looking into are:

    1. How to turn off the "More" element when there are no more records to load
    2. How to detect that there are no more records to load, and where to put that detection code.
    3. How to keep the list at the location that the user was at. Each load jumps back to the 1st item in the list

    Good luck!

    0 讨论(0)
  • 2021-02-10 07:14

    Remember also that this works only server side currently.

    Forum thread http://www.sencha.com/forum/showthread.php?105193-Store-pageSize

    0 讨论(0)
  • 2021-02-10 07:17

    In regards to the "load more vs. no more records" message -

    If you are writing a custom proxy (example here A Sencha Touch MVC application with PhoneGap), you set the total records in the returned Operation.

    If the total records are not yet known, you can do something like the below, where,

    1) if you are returning the requested limit of records, set the total to something larger than the records the store will now hold

    2) if returning < the requested limit of records, set the total to 1 (to force the "no more records message")

        //return model instances in a result set
        operation.resultSet = new Ext.data.ResultSet({
            records: contacts,
            //total  : contacts.length,
            total  : contacts.length === operation._limit ? (operation._limit * operation._page +1) : 1,
            loaded : true
        });
        //announce success
        operation.setSuccessful();
        operation.setCompleted();
        //finish with callback
        if (typeof callback == "function") {
            callback.call(scope || thisProxy, operation);
        }
    
    0 讨论(0)
  • I've had a similar issue with the ListPaging plugin in SenchaTouch 2, and managed to sort out the 'load more' message behaviour when the end of the data set is reached.

    This builds on what John Gordon has come up with (regarding specifying the pageSize and clearOnPageLoad config options), since these properties seem to be the same in Senchatouch 2. I haven't looked at SenchaTouch 1.x in detail. In SenchaTouch 2, all config options must be defined in a config property:

    Ext.define('MessagingApp.store.MessageThreads', {
        extend  : 'Ext.data.Store',
        requires: ['MessagingApp.model.MessageThread'],
    
        config:
        {
            model: 'MessagingApp.model.MessageThread',
    
            autoLoad: false,
            clearOnPageLoad: false,  // This is true by default
            pageSize: 10,            // This needs to be set for paging
    
            proxy: {
                type: 'jsonp',
                pageParam: 'currentPage',
                limitParam: 'pageSize',
                url: APIURL + '/message-app-service/GetMessageThreads',
                reader: {
                    type: 'json',
                    rootProperty: 'Data'
                }
            }
        }
    });
    

    In the view, where we specify the plugins, we can override the 'load more' and 'no more records' messages:

    {
        xtype:'dataview',
        store:'MessageThreads',
        id:'threadList',
        itemTpl:Ext.create('Ext.XTemplate',
            '<!-- template markup goes here -->',
            {
                //custom helper functions here
            }
        ),
        plugins:[
            {
                xclass:'Ext.plugin.ListPaging',
                autoPaging: true,
    
                // These override the text; use CSS for styling
                loadMoreText: 'Loading...',
                noMoreRecordsText: 'All messages loaded'
            }
        ]
    }
    

    The issue is that while our web service returns an array of records for a particular page, there is no overall total count property, which is needed for the plugin to determine when all records have been loaded. Hence as it is, the 'Load more' message will remain (issue #1 in the accepted solution). So in the init function of our controller, we have to attach an event handler for the load event on the store to hook into when a new page of data is received:

    Ext.define('MessagingApp.controller.Messages',
    {
        extend: 'Ext.app.Controller',
    
        config:
        {
            views: [
                'MessageThreads',
                // Other views referenced by this controller
            ],
    
            stores: [
                'MessageThreads'
            ],
    
            refs:
            {
                // References to UI elements by selector...
            }
        },
    
        init: function() {
            // Other internal initialisation...
    
            this.control(
            {
                // Selector-object pairs...
            });
    
            // Provide a means to intercept loads of each page of records
            var threadStore = Ext.getStore('MessageThreads');
            threadStore.addBeforeListener('load', this.checkForThreadListEnd, this);
        },
    
        // Remaining controller functions...
    
    });
    

    In the handler, we realise that we've reached the end of the data set when the number of records returned is less than the page size. If the total record count is a multiple of the page size, the last 'page' will have an empty array. Once the end of the data set has been identified, we update the totalCount config property of the store:

    checkForThreadListEnd: function(store, records, isSuccessful) {
        var pageSize = store.getPageSize();
        var pageIndex = store.currentPage - 1;    // Page numbers start at 1
    
        if(isSuccessful && records.length < pageSize)
        {
            //Set count to disable 'loading' message
            var totalRecords = pageIndex * pageSize + records.length;
            store.setTotalCount(totalRecords);
        }
        else
            store.setTotalCount(null);
    },
    
    // Other controller functions...
    

    Because this is a 'before' event handler, this property will be crucially updated before the plugin decides whether to display the 'load more' or 'no more records' messages. Unfortunately, the framework doesn't provide a means to hide the 'no more records' message, so this would have to be done via CSS.

    Hope this helps.

    0 讨论(0)
  • 2021-02-10 07:28

    Just to add what worked for me..

    If your server returns a totalCount and you want to set it you can use the totalProperty in the reader

    reader: {
                type: 'json',
                rootProperty: 'results',
                totalProperty: 'resultCount'
            }
    
    0 讨论(0)
提交回复
热议问题