UI Grid column is not sorting/filtering if we use a dynamically created custom column using splice/push
#6,814 建立於 2018年7月27日
倉庫指標
- Star
- (5,395 star)
- PR 合併指標
- (30 天內沒有已合併 PR)
描述
I am using UI grid * ui-grid - v4.2.0 - 2018-01-15* version. I tried all documented solutions but for a special type of custom column created splice, it is not working. As of now, it looks like UI grid doesn't support sorting if column is created and put into specific position using splice. See the column '% Target Deviation' is not sorting. When all columns are created, i am creating this column as i need values from other columns. Then i apply splice to show at 5th position. Note: All my other columns sorting is working perfectly!

I added a custom column using splice as below.
$scope.gridOptions.columnDefs.splice(5, 0, { name: 'TargetDeviation', type: 'number', width: '75', displayName: '% Target' + '\n' + 'Deviation', enableSorting: true, enableFiltering: false, headerTooltip: function () { return 'This column gives the % increase or decrease from the last build result with the target result.\nUse this value to prioritize the fixing for the performance issues.' }, field: 'TargetDeviation', sort: { direction: uiGridConstants, priority: 0 }, cellTemplate: '<div style="text-align:center">{{grid.appScope.GetComparisonValue(row.entity, grid.appScope.newestBuildName)}}</div>' });
The method which gives the content GetComparisonValue() is as below It returns a number type value
`$scope.GetComparisonValue = function (performanceTest, newestBuildName) {
var currentBuild = performanceTest.builds[newestBuildName];
if (currentBuild == null) return parseFloat("0.0");
var target = currentBuild.Target;
var median = currentBuild.performanceResult.Median;
if (target === 0 || median === 0) return parseFloat("0.0");
var unit = performanceTest.unit;
if (unit === "fps") {
return parseFloat((((median - target) / target) * 100).toFixed(1));
}
else {
return parseFloat((((target - median) / target) * 100).toFixed(1));
}
}`