2014-02-21 36 views
0
我有以下列在我的Ext.grid.Panel指定

排序ExtJS的網格面板中的自定義字段類型

{text: 'Home Country', dataIndex: 'homeCountryId', width: 250, xtype: 'country-column'}, 

xtype是「國列」,其定義爲:

Ext.define("RateManagement.view.Columns.CountryColumn", { 
    extend: 'Ext.grid.column.Column', 
    xtype: 'country-column',  
    text: 'Country', 
    editor: { xtype: 'country-combo', allowBlank: false, blankText: 'Country is required.'}, 
    renderer: function(val) { 
     var locationStore = Ext.data.StoreManager.lookup('RateManagement.store.CountryStore'); 
     var index = locationStore.findExact('value', val); 
     if (index != -1) { 
      var record = locationStore.getAt(index).data; 
      return record.label; 
     } 
    }, 
    sortable: true 
}); 

當我單擊網格中的列標題(「本國」)時,它根本不排序。

如何按record.label排序按字母順序排序?

編輯:這裏是如何我已經改變了我的模型:

{name:'homeLocationId', type: 'string'}, 
{name:'homeLocation', type: 'string', convert: function (newValue, model) { 
     // homeCountryId is appened for uniqueness and additional sort 
     return (newValue ? newValue : '') + '_' + model.get('homeLocationId'); 
    } 
}, 

這裏是我的格列:

{text: 'Home Location', dataIndex: 'homeLocationId', width: 250, xtype: 'location-column'}, 

回答

1

您可以設置標籤爲dataIndex與顯示器連接渲染「首頁國家' 這裏是工作樣品:http://jsfiddle.net/KLX5q/

enter image description here

// Monel 
Ext.define('CountryModel', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     { name:'homeCountryId', type:'int'}, 
     { name:'HomeCountryName', type:'string'}, 
     { name:'label', type:'string', 
      convert: function (newValue, model) { 
       // homeCountryId is appened for uniqueness and additional sort 
       return (newValue ? newValue : '') + '_' + model.get('homeCountryId'); 
     } 
     } 
    ] 
}); 

// store 
Ext.create('Ext.data.Store', { 
    storeId:'simpsonsStore', 
    fields:['homeCountryId', 'HomeCountryName', 'label'], 
    data:{'items':[ 
Ext.create('CountryModel',{ homeCountryId: 1, HomeCountryName: 'Australia', label:'nnnn' }), 
Ext.create('CountryModel',{ homeCountryId: 2, HomeCountryName:'Germany', label:'bbbb' }), 
Ext.create('CountryModel',{ homeCountryId: 3, HomeCountryName:'Russia', label:'aaaa' }), 
Ext.create('CountryModel',{ homeCountryId: 4, HomeCountryName:'United States', label:'zzzz' }) 
    ]}, 
    proxy: { 
     type: 'memory', 
     reader: { 
      type: 'json', 
      root: 'items' 
     } 
    } 
}); 

// gridpanel 
Ext.create('Ext.grid.Panel', { 
    title: 'Countries', 
    margin: 5, 
    frame: true, 
    store: Ext.data.StoreManager.lookup('simpsonsStore'), 
    columns: [ 
     { 
      text: 'HomeCountryName', 
      dataIndex: 'label', 
      flex: 1, 
      renderer: function(value, column, record){ 
       return record.data.HomeCountryName; 
      } 
     } 
     //,{ text: 'homeCountryId', dataIndex: 'homeCountryId' } // uncomment if need 
     //,{ text: 'display label', dataIndex: 'label' } 
    ], 
    height: 200, 
    width: 400, 
    renderTo: Ext.getBody() 
}); 
+0

我不知道你的意思'dataIndex:「標籤」,',我不知道你所說的'渲染器顯示「首頁Country''的意思。如果你有時間,可以用一個例子來詳細說明一下嗎? – user1477388

+1

我改變了我的答案) –

+0

感謝您的努力,但我在工作中遇到了一些麻煩。我有自己的國家,東道國,首頁位置和主機位置,所以我必須爲每個標籤創建單獨的標籤?我改變你的例子,使用HomeCountryName作爲'dataIndex',它似乎工作;不過,如果我在礦上做這個,那麼這個列就顯得空白。這裏是更新的jsfiddle http://jsfiddle.net/KLX5q/2/ – user1477388