我有一个按字母数字排序的自定义排序功能。我已将其设置为 ag-grid 中提到的比较器,但是我发现它不起作用。请放一些光。
var naturalSort = function(valueA, valueB, nodeA, nodeB, isInverted) {
var NUMBER_GROUPS = /(-?\d*\.?\d+)/g;
var aa = String(valueA).split(NUMBER_GROUPS),
bb = String(valueB).split(NUMBER_GROUPS),
min = Math.min(aa.length, bb.length);
for (var i = 0; i < min; i++) {
var x = parseFloat(aa[i]) || aa[i].toLowerCase(),
y = parseFloat(bb[i]) || bb[i].toLowerCase();
if (x < y) return -1;
else if (x > y) return 1;
}
return 0;
};
var columnDefs = [
{headerName: "Name", field: "name", width: 110, comparator: naturalSort}
];
var gridOptions = {
columnDefs: columnDefs,
rowData: null,
enableSorting: true
};