2016-09-22 36 views
2

一旦定義自定義排序爲列像GithubUI-Gridui-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; 


    }; 
+0

你可以發佈你在哪裏代碼調用'myAwesomeSortFn'? –

+0

請參閱上面的Github鏈接。 – MishaT

回答

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; 
    }; 
} 
+0

這就是我目前正在做的,它的工作原理,但也意味着您有超過40列的時間,加上字段更改時的可維護性成本。 – MishaT

+0

我將這個標記爲可接受的,因爲它似乎是不修改UI網格的唯一方法,我們最終要做的就是暴露列。 – MishaT

相關問題