2

一旦为GithubUI-Grid中的列定义自定义排序

如何从算法内部访问该列?

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;


    };  
4

1 回答 1

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;
    };  
}
于 2016-09-27T22:01:10.407 回答