【问题标题】:ExtJS data store does not sortExtJS 数据存储不排序
【发布时间】:2013-08-31 19:05:23
【问题描述】:

我正在使用 ExtJS 4.2 并创建了一个带有排序器的商店。商店从 JSONP Web 服务调用加载数据就好了,但它拒绝排序。下面是我的模型、存储和加载调用的表示。

型号:

Ext.define('Desktop.models.products.DtoProductFamilyModel', {
extend: 'Ext.data.Model',
fields: [
    {
        name: 'ProductFamilyId',
        type: 'string',
        useNull: false,
        defaultValue: Util.getBlankGuid()
    },
    {
        name: 'ParentProductFamilyId',
        type: 'string',
        useNull: true,
        defaultValue: Util.getBlankGuid()
    },
    {
        name: 'BaseItemId',
        type: 'string',
        useNull: true,
        defaultValue: Util.getBlankGuid()
    },
    {
        name: 'Name',
        type: 'string',
        useNull: false,
        defaultValue: ''
    },
    {
        name: 'DisplayName',
        type: 'string',
        useNull: false,
        defaultValue: ''
    },
    {
        name: 'ExternalReferenceId',
        type: 'string',
        useNull: true,
        defaultValue: null
    }
]
});

商店:

Ext.define('Desktop.stores.products.GetProductFamiliesStore', {
extend: Ext.data.Store,
model: 'Desktop.models.products.DtoProductFamilyModel',
proxy: {
    type: 'jsonp',
    url: 'http://www.somejsonpwebservice.com',
    method: 'GET',
    pageParam: false, 
    startParam: false, 
    limitParam: false,
    timeout: 9000000,
    noCache: true,
    headers: { 'Content-Type': 'application/json;charset=utf-8' },
    sorters: [{
        property: 'Name',
        direction: 'ASC'
    }],
    sortRoot: 'Name',
    sortOnLoad: true,
    remoteSort: false,
    reader: {
        type: 'json'
    }
}
});

利用商店的组合框组件:

    {
        xtype: 'combo',
        zzid: 'cmbProductManufacturersFamily',
        store: 'Desktop.stores.products.GetProductFamiliesStore',
        width: 250,
        labelWidth: 50,
        forceSelection: true,
        fieldLabel: Util.translate('Family'),
        emptyText: 'Select Product Family',
        margin: '0 0 0 10',
        displayField: 'Name',
        valueField: 'ProductFamilyId'
    }

加载存储的实际调用:

this.stoProductFamilies = this.cmbProductManufacturersFamily.getStore();
this.stoProductFamilies.load()

数据加载正常,但商店拒绝对我的数据进行排序。我正在将 100 多个动态记录加载到组合框中,并且需要此功能正常工作。如果有人能提供关于我做错了什么的见解,我将不胜感激。

【问题讨论】:

    标签: javascript sorting extjs store


    【解决方案1】:

    sortOnLoad、remoteSort 和 sorters 配置没有在代理上设置,而是在 store 上设置如下:

    Ext.define('Desktop.stores.products.GetProductFamiliesStore', {
        extend: Ext.data.Store,
        model: 'Desktop.models.products.DtoProductFamilyModel',
        sorters: [{
            property: 'Name',
            direction: 'ASC'
        }],
        sortRoot: 'Name',
        sortOnLoad: true,
        remoteSort: false,
        proxy: {
           type: 'jsonp',
           url: 'http://www.somejsonpwebservice.com',
           method: 'GET',
           pageParam: false, 
           startParam: false, 
           limitParam: false,
           timeout: 9000000,
           noCache: true,
           headers: { 'Content-Type': 'application/json;charset=utf-8' },
           reader: {
               type: 'json'
           }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2013-08-25
      • 2011-07-25
      • 1970-01-01
      • 2020-11-13
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多