angular-ui/ui-grid

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

Open

#6814 aperta il 27 lug 2018

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)JavaScript (2496 fork)batch import
help wanted

Metriche repository

Star
 (5395 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor