angular-ui/ui-grid

UI Grid column is not sorting/filtering if we use a dynamically created custom column using splice/push

已關閉

#6,814 建立於 2018年7月27日

 (4 則留言) (0 個反應) (0 位負責人)JavaScript (2,496 個分叉)batch import
help wanted

倉庫指標

星標
 (5,395 顆星)
PR 合併指標
 (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!

image

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));
        }
    }`    

貢獻者指南