sencha list paging plugin load more

本文介绍了如何在 Sencha Touch 中使用 List Paging 插件实现数据分页加载,并解决了分页过程中遇到的问题,如配置 Store 来支持分页、禁用加载更多提示等。


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 plugin in my list

this.myList = new Ext.List({
  store: this.myStore,
  plugins: [{
    ptype: 'listpaging',
    autoPaging: false
  }],
  itemTpl: '...'
});

a 'Load More' text and a loading image is added to the end of the list.

But i don't know how to configure my store to enable this plugin to be able to load more data.

App.regStore('MyStore', {
 model: 'myModel',
 proxy: {
    type: 'ajax',
    url: 'http://mydomain.com/json?howmany=10&page=1',
    reader: {
        type: 'json',
        root: 'results'
    }
  }
});

App.stores.myStore = Ext.StoreMgr.get('MyStore');

How can i configure my store so when i tap "Load more", the store brings up page 2 and add them to the list automatically?

link | improve this question

 
Was this post useful to you?      

3 Answers

up vote 0 down vote accepted

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!

link | improve this answer
 
Thanks for your answer, also please let me know if anything else comes up. –  keune  Sep 9 '11 at 19:44
 
item 3 in my outstanding items was a fault of my code. I had a piece of code that would force bringing the the user back to the top of the list on refresh of the data, so as to avoid another rendering error with sencha touch's list component. The bug manifests when the data replacing the list is less than what was originally there, causing the list to misrender. –  John Gordon  Sep 28 '11 at 12:42
 
Have you been able to find a solution to your first issue: "How to turn off the "More" element when there are no more records to load"? –  Ross  Feb 29 at 4:53
feedback

Remember also that this works only server side currently.

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

link | improve this answer
 
feedback

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 andclearOnPageLoad 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 aconfig 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 theinit 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 totalCountconfig 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.

link | improve this answer
 
Thanks for d_mcg solution. there is other issue: the "No more records" link 's still clickable and it sends a request to the server once clicked. How do you resolve this ? many thanks :) –  Bogie  Mar 29 at 2:46
 
You're welcome :-) I haven't found an easy way to disable that button, mainly because SenchaTouch only provides the means to set the text of this button in either state (which is applied via an XTemplate in the 'private'loadTpl config property). You may be able to work some magic to intercept the tap event of this button and return false (which cancels the event), or use a funky CSS selector to hide the button in its 'no more records' state. You can see the internals of how Sencha does it at docs.sencha.com –  d_mcg  Mar 30 at 10:59
 
Forgot to say - you can hover over the green heading (i.e. the class name) to reveal the "View source..." link for that class. I've found that very helpful for figuring out some of the extra details that the documentation doesn't mention. –  d_mcg  Mar 30 at 11:07
feedback


这个是完整源码 java实现 大数据 Spark 可视化大屏+Kafka+SpringBoot+Vue3 【大数据毕业设计】基于Spark实时社交媒体舆情分析与趋势预测(Java版本+可视化大屏+Kafka+SpringBoot+Vue3) 源码+论文 完整版 数据库Mysql 随着微博、抖音、知乎、小红书等社交媒体平台的快速发展,网络舆情呈现出数据规模大、传播速度快、情绪演化复杂等特点。传统离线批处理方式难以满足舆情监测对时效性的要求,亟需构建一套能够支撑实时采集、流式计算、情感分析与趋势预测的综合系统。本文围绕“基于Spark实时社交媒体舆情分析与趋势预测”课题,设计并实现了一套前后端分离的舆情分析平台。系统后端采用Java语言与Spring Boot框架构建RESTful服务,结合JWT完成管理员身份认证与权限控制;数据处理层引入Spark思想的流式窗口统计与Kafka消息缓冲机制,对社交媒体帖文进行情感倾向识别、热度指数计算和按小时窗口聚合;趋势预测模块基于历史热度序列构建多元线性回归模型,输出未来窗口的热度预测值,并采用RMSE、MAE、MAPE等指标评价预测效果;前端采用Vue3、Vue Router、Pinia、Element Plus与ECharts实现管理后台与数据可视化大屏,支持帖文管理、话题管理、实时舆情查看、趋势对比和个人中心维护等功能。数据库选用MySQL,库名为db_social_opinion,核心业务表均以t_前缀命名,覆盖管理员、用户、平台、话题、帖文、实时统计、预测结果与误差指标等实体。测试结果表明,系统能够稳定完成舆情事件模拟、实时统计刷新与趋势预测展示,界面日期时间统一采用“2026-11-02 17:25:17”格式,满足本科毕业设计对完整性、规范性与可演示性的要求。本文工作对高校舆情教学实验、中小规模舆情监测系统原型开发具有一定
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值