onGridReady吗? api.setColumnDefs无法根据搜索条件(ag-Grid角度1.6)更新动态标头

时间:2018-09-03 07:15:00

标签: dynamic header ag-grid angular1.6

我正在使用angular 1.6,ag-grid显示动态网格列标题。 这是网页上的过滤器。使用“短名称”过滤器动态更改网格列标题。当我第一次单击提交时,它可以工作。但是没有刷新,当我在短名称下拉列表中选择更多项并再次单击提交按钮时。 $ scope.poGridOptions.api.setColumnDefs($ scope.poResColumnDefs)不起作用。我环顾四周,一些文档说使用api之前需要准备好网格。或添加$ timeout。但是我不知道如何在角度1.6中使用它。希望在这里得到样品。

部分关键代码如下。

 <div class="container">
                        <div   ng-style ="getSecondaryTableHeight()";
                              ag-grid="poGridOptions"
                              class="ag-theme-balham ag-basic"><!--class="ag-theme-balham ag-basic"-->
                        </div>

                    </div>
var header2Arr = ["Target","Closed","Pending","Testing %Completed","Defects","%Defects"];
function sixColumn(header1Arr, header2Arr) {
        header1Arr.forEach(function (checkpointItem,index) {
            var columnItemObj = {};
            var columnsName =[];

            if(index%2===0){
                var checkpointItemCss = 'checkpointItemCss-class';
            }else{
                var checkpointItemCss = 'checkpointItemCssEven-class';
            }
            header2Arr.forEach(function (oneColumn) {
                var columnString = checkpointItem + ' ' + oneColumn;
                columnsName.push(columnString);
            });

            columnItemObj =    {
                headerName: checkpointItem,
                headerClass: checkpointItemCss,
                children: [
                    //Target
                    {headerName: header2Arr[0],
                        headerClass: checkpointItemCss,
                        field: columnsName[0],
                        width: 52
                        //,cellRenderer: percentCellRenderer
                    },
                    //Closed
                    {headerName: header2Arr[1],
                        headerClass: checkpointItemCss,
                        field: columnsName[1],
                         width: 56
                        //,cellRenderer: percentCellRenderer
                    },
                    //pending
                    {headerName: header2Arr[2],
                        headerClass: checkpointItemCss,
                        field: columnsName[2],
                        width: 64
                        //,cellRenderer: percentCellRenderer
                    },
                    //Testing Completed
                    {headerName: header2Arr[3],
                        headerClass: checkpointItemCss,
                        field: columnsName[3],
                        width: 136
                    },
                    //Defects
                    {headerName: header2Arr[4],
                        headerClass: checkpointItemCss,
                        field: columnsName[4],
                        width: 62,
                        cellRenderer: percentCellRenderer
                    },
                    //%Defects
                    {headerName: header2Arr[5],
                        headerClass: checkpointItemCss,
                        field: columnsName[5],
                        width: 72
                    }
                ]
            };
            if(selectedStrategy[0] === "SOX"){
                $scope.resColumnDefs.push(columnItemObj);
            }else if(!selectedStrategy.length)
            {
                if(header1Arr[0].indexOf("SOX")>-1 || header1Arr[0].indexOf("Total")>-1){
                $scope.resColumnDefs.push(columnItemObj);
                }else{
                    $scope.poResColumnDefs.push(columnItemObj);
                }

               // console.log("hahahah");
            }else if(selectedStrategy[0] === "Secondary"){
                $scope.poResColumnDefs.push(columnItemObj);
            }

        });
    }
//$scope.poCheckpointArr dynamic array which user selected from the short name dropdown list
sixColumn($scope.poCheckpointArr,header2Arr);
$scope.poGridOptions.api.setColumnDefs($scope.poResColumnDefs);

0 个答案:

没有答案