【问题标题】:Setting the reader on a extjs store在 extjs 商店上设置阅读器
【发布时间】:2011-12-07 17:53:26
【问题描述】:

我在 extjs4 上有一个商店,它返回一个对象列表,我想设置 reader 属性以便能够对元素进行计数,以便之后可以使用分页。

作为参考,extjs 使用的示例已经带有一个计数属性(totalCount)和列出的对象类型(主题),而我的没有它,只有列表。

供参考: example

另外,在我的代码中,网格无法识别每页结果的限制,但分页工具栏可以:

var sm = Ext.create('Ext.selection.CheckboxModel');

Ext.define('Cliente', {
    extend: 'Ext.data.Model',
    fields: [{
        name: 'ID',
        type: 'int'
    }, {
        name: 'Nome',
        type: 'string'
    }, {
        name: 'Email',
        type: 'string'
    }, {
        name: 'RazaoSocial',
        type: 'string'
    }, {
        name: 'TipoDeCliente',
        type: 'string'
    }],
    idProperty: 'ID'

});

var store = Ext.create('Ext.data.Store', {
    pageSize: 3,
    model: 'Cliente',
    remoteSort: true,
    proxy: {
        type: 'ajax',
        url: 'http://localhost:4904/Cliente/ObterClientes',
        extraParams: {
            nome: '',
            tipopessoa: '',
            email: '',
            cpf: '',
            estado: '',
            cidade: '',
            cep: ''
        },
        reader: {
            type: 'json',
            root: 'data'
        },
        simpleSortMode: true
    },
    sorters: [{
        property: 'Email',
        direction: 'DESC'
    }]
});

var pluginExpanded = true;
var grid = Ext.create('Ext.grid.Panel', {
    width: 500,
    height: 250,
    title: 'Array Grid',
    store: store,
    selModel: sm,

    loadMask: true,
    viewConfig: {
        id: 'gv',
        trackOver: false,
        stripeRows: false
    },
    columns: [{
        id: 'gridid',
        text: "ID",
        dataIndex: 'ID',
        hidden: true
    }, {
        text: 'Nome',
        width: 150,
        sortable: true,
        dataIndex: 'Nome'
    }, {
        text: 'Tipo de Cliente',
        width: 100,
        sortable: true,
        dataIndex: 'TipoDeCliente'
    }, {
        text: 'Email',
        width: 150,
        sortable: true,
        dataIndex: 'Email'
    }],
    bbar: Ext.create('Ext.PagingToolbar', {
        store: store,
        displayInfo: true,
        displayMsg: 'Exibindo clientes {0} - {1} of {2}',
        emptyMsg: "Nenhum cliente"
    }),
    renderTo: 'clientes',
});

store.loadPage(1);

【问题讨论】:

    标签: extjs4


    【解决方案1】:

    商店需要总计数来计算分页参数并显示总数。您的服务器端实现必须更改以将该计数添加到您的数据中。 也像这样store.load(); 加载数据而不是 loadPage。

    编辑:这里还有一个额外的逗号:renderTo: 'clientes', 我建议通过 JSLint 运行您的代码。

    【讨论】:

    • 感谢 DmitryB,但我找到了解决问题的另一种方法:我将此通道添加到存储函数 autoLoad: {start: 0, limit: 3},然后我让我的方法接收这两个参数,并使用我列表中的“GetRange”来获取所需的分页
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-13
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 2014-03-11
    • 1970-01-01
    相关资源
    最近更新 更多