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

标签 javascript string sorting extjs grid

我有一个网格,其中有一列将 float 记录字段呈现为字符串。因此,当我对列进行排序时,它是按 String 格式排序的,因此以错误的方式排序:

enter image description here

我尝试过不同的解决方案。我理解它应该起作用的是使用 sortType 函数。但到目前为止我还不能……

这些是我的代码的重要部分。

我用数据加载网格的模型:

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);
        }
    },
    .....

我的网格列受影响:

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');
        }
    }, {
    .....

这两个列都没有按照我的预期对数据进行排序。

注意(可能有用):字符串格式为“0.000,00”

我该如何解决这个问题?

最佳答案

请看这个: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);
    }
}

关于javascript - ExtJS 将字符串的网格列排序为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29947269/

相关文章:

python - 从 pandas 的字符串列中删除非 ASCII 字符

java - 在 Lucene TFIDF 中为特定条件自定义分数

javascript - 如何保持 Bootstrap 下拉复选框列表下拉

javascript - 在生成 d3 图之前过滤数据

c - 尝试声明字符串数组时出现段错误

sorting - 在SSRS报表中进行排序以覆盖组排序

sorting - 如何在 GPU 上对实例缓冲区进行排序?

javascript - Material ui 弹出窗口中的意外行为

javascript - ReactJS "TypeError: Cannot read property ' array' of undefined"

python - Python 中的变量替换