首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每页项目不生效[Extjs]

每页项目不生效[Extjs]
EN

Stack Overflow用户
提问于 2014-10-09 22:17:04
回答 1查看 525关注 0票数 0

我已经为分页编写了extjs代码。它向我展示了网格中的所有数据,但我设置了itemsPerPage = 2。我认为这是一个小错误,但我对extjs和所有的东西都是新手,所以我不能弄清楚。我试过了,但到目前为止还没成功。

代码语言:javascript
复制
Ext.onReady(function () {
var itemsPerPage = 2;   // set the number of items you want per page

var store   =   Ext.create('Ext.data.Store', {
    storeId: 'employeeStore',
    autoLoad: false,
    pageSize: itemsPerPage, 
    fields: ['firstname', 'lastname', 'seniority', 'dep', 'hired'],
    data: [{
        firstname: "Michael",
        lastname: "Scott"
    }, {
        firstname: "Dwight",
        lastname: "Schrute"
    }, {
        firstname: "Jim",
        lastname: "Halpert"
    }, {
        firstname: "Kevin",
        lastname: "Malone"
    }, {
        firstname: "Angela",
        lastname: "Martin"
    }],
    proxy: {
        type: 'ajax',
        url: 'example.json',  // url that will load data with respect to start and limit params
        reader: {
            type: 'json',
            root: 'blah',
            totalProperty: 'total'
        }
    }
});

// specify segment of data you want to load using params
store.load({
    params:{
        start:0,    
        limit: itemsPerPage
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Pagination',        
    store: store,       
    columns: [{
        text: 'First Name',
        dataIndex: 'firstname',
        field: 'textfield',
        flex : 1,   
    }, {
        text: 'Last Name',
        dataIndex: 'lastname',
        flex : 1,   
            field:{
                xtype:'textfield',
                allowBlank:false
            }           
    }],
    id : 'SimpleGrid',
    width: 500,
    dockedItems: [{
        xtype: 'pagingtoolbar',
        store: store,   // same store GridPanel is using
        dock: 'bottom',
        displayInfo: true
    }],
    renderTo: Ext.getBody()
});

});

要使用分页,请在第一次加载存储区时将分页要求传递给服务器。

代码语言:javascript
复制
store.load({
params: {
    // specify params for the first page load if using paging
    start: 0,          
    limit: myPageSize,
    // other params
    foo:   'bar'
}

});

这里我用的是extjs + Grid + Panel。

致以亲切的问候,

EN

回答 1

Stack Overflow用户

发布于 2014-10-09 23:04:49

如果您查看comment to url字段:

代码语言:javascript
复制
proxy: {
    ...
    url: 'example.json',  // url that will load data with respect to start and limit params
    ...
}

extjs在加载所有需要的参数时向服务器发送请求。例如: extjs,因此您应该将其限制在服务器上,然后发送回example.json?start=0&limit=2&page=1

在这里,您可以查看工作示例,其中限制是手动处理的。

http://jsfiddle.net/jardalu/TE4ah/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26280776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档