动态AG-GRID Angular 2中的刷新问题

时间:2017-11-06 07:02:05

标签: angular

我正在使用ag-grid,并且动态填充了gridoptions。问题在于“全选”复选框选择gridoption没有刷新。 我试过这两种方法:

this.achcGridOptions.api.setRowData(this.achcGridOptions.rowData)
this.achcGridOptions.api.setColumnDefs(this.dynamicolumn(element));

但我收到错误

  

“无法读取未定义的属性'api'”

public dynamiccolumnchc(index:number){         this.broaddomain = this.examretun [index] [“broadDomainAbbr”];         返回this.getgridcolumns(this.achcGridOptions,this.examretun [index] [“broadDomainName”] +“(”+ this.examretun [index] [“broadDomainAbbr”] +“)”,this.examretun [index] [“broadDomainAbbr “]);     }     public dynamiccolumnsld(index:number){         this.broaddomain = this.sldretun [index] [“broadDomainAbbr”];         返回this.getgridcolumns(this.asldGridOptions,this.sldretun [index] [“broadDomainName”] +“(”+ this.sldretun [index] [“broadDomainAbbr”] +“)”,this.sldretun [index] [“broadDomainAbbr “]);     }     public dynamiccolumncog(index:number){         this.broaddomain = this.cogretun [index] [“broadDomainAbbr”];         返回this.getgridcolumns(this.acogGridOptions,this.cogretun [index] [“broadDomainName”] +“(”+ this.cogretun [index] [“broadDomainAbbr”] +“)”,this.cogretun [index] [“broadDomainAbbr “]);     }     public dynamicolumn(headertext:string){         返回[             {                 headerName:“dataOrganizerId”,field:“dataOrganizerId”,suppressFilter:true,hide:true             },             {                 headerName:“”,field:“compositeType”,width:100,suppressFilter:true             },             {                 headerName:headertext,field:“batteryCompTestName”,width:280,suppressFilter:true //,

        },
        {
            headerName: "Score", field: "standardScore", suppressFilter: true, width: 80
        },
        {
            headerName: "", field: "isTransferred", suppressFilter: true, width: 70,
            headerCellRenderer: this.CellHeader,
            cellRenderer: this.transferCellRenderer,
        },
        {
            headerName: "", field: "isDelete", suppressFilter: true, width: 70,
            cellRenderer: this.deleteCellRenderer,
        }
    ];
}
public getgridcolumns(index: GridOptions, titleheader: string, broadDomainID: string) {
    this.selectedxbascores = [];
    this.pswdata.forEach(element => {
        if (element.broadDomain == broadDomainID)
            this.selectedxbascores.push(element);
    });
    if (this.selectedxbascores.length == 0) {
        this.selectedxbascores.push({});
        this.selectedxbascores.push({});
        this.selectedxbascores.push({});
    }
    else if (this.selectedxbascores.length == 1) {
        this.selectedxbascores.push({});
        this.selectedxbascores.push({});
    }
    else if (this.selectedxbascores.length == 2) {
        this.selectedxbascores.push({});
    }
    index = <GridOptions>{};
    index.columnDefs = this.dynamicolumn(titleheader);
    index.rowData = this.selectedxbascores;
    index.rowHeight = 50;
    index.enableCellChangeFlash =true;
    index.enableFilter = true;
    index.headerHeight = 50;
    index.context = {
        batteryService: this,
    }
    index.onGridReady = function (params) {
        params.api.sizeColumnsToFit();
    }
    return index;
}
selectAll(e) {
    debugger
    var checked = e.target.checked;
    this.checkBoxValue = checked;
    var count = 0;

    if (this.pswdata.length > 0) {
        var testCount = 0;
        this.pswdata = this.pswdata.map(function (a) {
            if (!isNaN(parseInt(a["standardScore"]))) {
                a["isTransferred"] = checked;
                count = count + 1;
                testCount = testCount + 1;
            }
            return a;
        });
        if (testCount > 0)
            this.pswdata.forEach(element => {
                //this.achcGridOptions.api.setRowData(this.achcGridOptions.rowData)
                //this.achcGridOptions.api.setColumnDefs(this.dynamicolumn(element));
            });
            var gridDiv=document.querySelector('#chcGrid');
             alert(gridDiv);
            //gridDiv.tr

    }

    if (count == 0) {
        e.preventDefault();
        e.target.checked = false;
        e.target.parentNode.className = "gridchkbox link";

    }
}

1 个答案:

答案 0 :(得分:0)

听起来你从未将GridOptions分配给实例变量achcGridOptions。您的组件.ts文件应如下所示:

gridOptions: GridOptions;

constructor() { this.gridOptions = { ... } }

并在模板中

<ag-grid-angular class="ag-fresh"[gridOptions]="gridOptions"></ag-grid-angular>