angular-ui/ui-grid

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

Open

#6.814 aberto em 27 de jul. de 2018

Ver no GitHub
 (4 comments) (0 reactions) (0 assignees)JavaScript (2.496 forks)batch import
help wanted

Métricas do repositório

Stars
 (5.395 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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

Guia do colaborador