我有一个网格视图,其中有4列,如下所示:
IP | Name | Status |Value
192.168.1.3 |MAS | UP |x
192.168.1.5 |HGR | UP |Y
192.168.1.10 |UYR |DOWN |Z
192.168.1.7 |IOR |UP |P
我正在使用ng-grid框架来显示这些。这里的排序不适用于ip address列,它对其他列的工作正常。我的列定义如下:-
columnDefs : [{
field : 'ip',
displayName : 'IP',
width : '25%'
},
{
field : 'name',
displayName : 'NAME',
width : '25%'
},
{
field : 'status',
displayName : 'Status',
width : '25%'
},
{
field : 'value',
displayName : 'Value',
width : '25%'
}];
有什么想法吗?
默认情况下,该列应进行字符串排序。如果您的意思是说,它应该进行数字排序而不是字符串排序,则可以尝试对ip列使用自定义排序功能,
columnDefs: [
{
field: 'ip',
displayName: 'IP',
width: '25%',
sortFn: function (a, b) {
if (a == b) return 0;
if ( +a.replace(/\./g, '') < +b.replace(/\./g, '')) return - 1;
return 1;
}
},
{
field: 'name',
displayName: 'NAME',
width: '25%'
},
{
field: 'status',
displayName: 'Status',
width: '25%'
},
{
field: 'value',
displayName: 'Value',
width: '25%'
}
];
希望这可以帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句