1
votes

I have a grid with a column that renders a float record field as a String. So, when I sort the column, this it's sorted with the String format and therefore, in a wrong way:

enter image description here

I've tried different solutions. The one that I understand it should works is the use of a sortType function. 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"

How can I solve this?

1
ext version, please? - Yellen

1 Answers

2
votes

Please see this: 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);
    }
}