【问题标题】:Extjs Grid - no current pageExtjs Grid - 没有当前页面
【发布时间】:2013-02-03 09:24:24
【问题描述】:

并提前感谢您在此问题上的帮助。

我有一个 extjs 4.1 网格,填充了从服务器加载的 json。分页是远程的,每个 25 个项目的块都从服务器正确地作为有效的 json 提供,并且在 totalProperty 中具有正确的值。就加载和分页而言,一切功能正常,分页栏中没有页码。 它看起来像这样。 好的...我不允许发布图片...所以这是一个链接 it looks like this

这里是相关代码。如果有助于解决问题,我可以发布其他代码。

var theStore = Ext.create('Ext.data.Store',
    {
        model: 'SearchResult',
        pageSize: 25,
        remoteSort: true,
        proxy:
        {
            type: 'ajax',
            url: '/Search/SubmitSimpleQuery',
            reader:
            {
                type: 'json',
                root: 'Results',
                totalProperty: 'totalHits'
            },
            extraParams:
            {
                searchText: theSearchText,
                beginDate: theBeginDate,
                endDate:theEndDate,
                collectionMatch:theCollection
            }
        }
    });
theStore.load();





var grid = Ext.create('Ext.grid.Panel',
    {
        store: theStore,
        width: '100%', 
        height: '100%', 
        columns:
        [

            {
                text: 'Title',
                dataIndex: 'title',
                width: '60%'

            },

            {
                text: 'Published Date',
                dataIndex: 'pubDate_ymd',
                renderer: renderDate
            },
            {
                text: 'Released Date',
                dataIndex: 'releaseDate_ymd',
                renderer: renderDate
            },
            {
                text: 'From',
                dataIndex: 'from',
                hidden: true

            },
            {
                text: 'To',
                dataIndex: 'to',
                hidden: true

            }
        ],
        dockedItems: [
        {
            xtype: 'pagingtoolbar',
            dock: 'bottom',
            store: theStore,
            displayInfo: true,
            displayMsg: 'Displaying results {0} - {1} of {2}',
            emptyMsg: 'No results'
        }]

    });


Ext.create('Ext.panel.Panel',
{
    bodyPadding:25,
    width:'100%',
    renderTo:Ext.getBody(),
    items:[
        grid
    ]

});

totalproperty 正确地通过他的 json 进入 - 例如 108 导致 5 页。所有寻呼工作。当分页到第 2 页时,page:2 , start:25, limit: 25 全部传递给服务器,所以 ext 知道它是什么页面,但它没有进入当前页面框。然后我需要将该页面值设置为代理或存储上的属性吗?

我被难住了,我已经用头撞这个有一段时间了。

谢谢。

顺便说一句, 这是一个类似的问题 ExtJS grid panel not showing page number 但它(显然?)已修复将分页栏添加到网格上的停靠编辑项,正如您在上面看到的那样。

【问题讨论】:

    标签: extjs grid paging extjs4.1


    【解决方案1】:

    来自 Sencha API 文档:

    要使用分页,需要在Store上设置一个pageSize配置, 并在第一次存储时将分页要求传递给服务器 已加载。

    store.load({
        params: {
            // specify params for the first page load if using paging
            start: 0,
            limit: myPageSize,
            // other params
            foo:   'bar'
        }
    });
    

    http://docs.sencha.com/ext-js/4-1/#!/api/Ext.toolbar.Paging

    我认为您的问题可能是您在没有任何此类参数的情况下手动调用theStore.load()。我认为您根本不需要调用它。

    【讨论】:

    • 检查一下是个好主意。我确实在商店中设置了页面大小。我刚刚检查了分页要求,它们会自动发送到服务器。因此,在初始加载 Page=1、start=0 和 limit=25 时正确发送。 (显式的 store.load 更多的是调试和尝试更好地隔离事物的结果,不幸的是,它也无法进行自动加载)
    • 您是否检查了页面上的元素以验证value 属性是否为空?在图片中,输入字段的样式看起来很奇怪,可能是该值在视图中被遮挡了?