简体   繁体   English

ExtJS将字符串的网格列排序为float

[英]ExtJS sort grid column of string as float

I have a grid with a column that renders a float record field as a String. 我有一个带有列的网格,该列将浮点记录字段呈现为String。 So, when I sort the column, this it's sorted with the String format and therefore, in a wrong way: 因此,当我对列进行排序时,它以String格式排序,因此,以错误的方式进行排序:

在此处输入图片说明

I've tried different solutions. 我尝试了不同的解决方案。 The one that I understand it should works is the use of a sortType function. 我了解它应该起作用的一个是使用sortType函数。 But I haven't bee able so far... 但到目前为止我还没有能力...

These are the important pieces of my code. 这些是我代码的重要部分。

My model to load the grid with data: 我的模型用数据加载网格:

Ext.define('AMA.model.AssetModel', {
extend: 'Ext.data.Model',

fields: [
    {name: 'Account', type: 'string'},
    {name: 'AltLabel'},
    {name: 'Amortizable', type: 'int'},
    {name: 'AmortizationsVNC',
        type: 'float',
        convert: function(value,model){
            return parseFloat(Math.round(value * 100) / 100).toFixed(2);
        }
    },
    {name: 'AssetsAccountingPrice',
        type: 'float',
        convert: function(value,model){
            return parseFloat(Math.round(value * 100) / 100).toFixed(2);
        }
    },
    .....

My grid columns affected: 我的网格列受到影响:

items: [{
xtype: 'grid',
reference:'grdGestion',
id:'grdGestion',
//store: assetsStore,
//height: Ext.getCmp('MainContenedor').lastBox.height-150-50,
columns: [{
    .....

    },{
        text: l10n.translate('Coste'),
        flex: 1,
        sortable: true,
        dataIndex: 'AssetsAccountingPrice',
        xtype: 'numbercolumn',
        decimalPrecision: 2,
        decimalSeparation: ',',
        thousandSeparation: '.'
    }, {
        text: l10n.translate('VNC'),
        flex: 1,
        sortable: true,
        dataIndex: 'AmortizationsVNC',
        renderer: function(value){ 
            return Ext.util.Format.number(value, '0,000.00');
        }
    }, {
    .....

Neither of the two coumns sort the data as I would expected. 两个列都没有像我期望的那样对数据进行排序。

NOTE (maybe useful): the String format is "0.000,00" 注意 (可能有用):字符串格式为“ 0.000,00”

How can I solve this? 我该如何解决?

Please see this: FIDDLE 请看此: FIDDLE

{
    name:'fieldName', 
    type: 'float', 
    sortType: 'asFloat', // you just need to add this 
    convert: function(value,model) {
        return parseFloat(Math.round(value * 100) / 100).toFixed(2);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM