我有一个网格,其中有一列将 float 记录字段呈现为字符串。因此,当我对列进行排序时,它是按 String 格式排序的,因此以错误的方式排序:
我尝试过不同的解决方案。我理解它应该起作用的是使用 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/