ui-grid 从自定义排序算法中获取当前列(字段)名称?
ui-grid get the current column (field) name from inside a custom sorting algorithm?
中的列定义了自定义排序
如何从算法内部访问该列?
var myAwesomeSortFn = function(a,b, rowA, rowB, direction){
// "Need to access the name (field) of column being sorted here";
var column = "No Idea"
console.log("sorting by column " + column );
if (a == b) return 0;
if (a < b) return -1;
if (a > b) return 1;
};
您可以尝试以下方法...
{ field: 'lastName', displayName: 'Last Name', sortingAlgorithm: MyService.getSortingAlgorithm('lastName') },
然后在服务中定义(如果您愿意,也可以在您的范围中定义)
getSortingAlgorithm: function (columnName) {
return function(a, b, rowA, rowB, direction) {
console.log("sorting by column " + columnName);
if (a == b) return 0;
if (a < b) return -1;
if (a > b) return 1;
};
}
如何从算法内部访问该列?
var myAwesomeSortFn = function(a,b, rowA, rowB, direction){
// "Need to access the name (field) of column being sorted here";
var column = "No Idea"
console.log("sorting by column " + column );
if (a == b) return 0;
if (a < b) return -1;
if (a > b) return 1;
};
您可以尝试以下方法...
{ field: 'lastName', displayName: 'Last Name', sortingAlgorithm: MyService.getSortingAlgorithm('lastName') },
然后在服务中定义(如果您愿意,也可以在您的范围中定义)
getSortingAlgorithm: function (columnName) {
return function(a, b, rowA, rowB, direction) {
console.log("sorting by column " + columnName);
if (a == b) return 0;
if (a < b) return -1;
if (a > b) return 1;
};
}