Dynamically change headerName ag-grid Angular 2?


Valitskiy Dmitriy

I have the following code:

public fy: string = "17";
let months = ['July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March', 'April', 'May', 'June',];

        function headerCellRendererFunc(year, params) {
            const eHeader = document.createElement('span');
            eHeader.innerText = `${params.colDef.headerName} ${year}`;
            return eHeader;
        }

        const januaryIndex = months.indexOf('January');
        months.map((month, index, arr) => {
            const year = januaryIndex === 0 || index > januaryIndex ? this.fy : this.fy + 1;

            return <ColDef>{
                headerName: month,
                headerCellRenderer: headerCellRendererFunc.bind(null, year),
                field: `data.${month}`,
                editable: isEditable,
                valueGetter: cellMonthValueGetter(month, index),
                cellFormatter: cellMonthValueFormatter,
                newValueHandler: cellMonthNewValueHandler(month),
                width: 100,
            };
        }).forEach((colDef) => colDefs.push(colDef));

and this function:

refresh(): void {
    let jobId = +this.route.snapshot.parent.params['id'];
    this.jobService.getJob(jobId).then(result => {
        this.job = result.Object;
        this.fy = result.Object.FinancialYearName;
        this.jobService.getTimePhasing(jobId).then(result => {
            this.setModel(result.Object);
        });
    });
}

As you can see, the FY mod will be changed after request. How can I change it in the column? I tried calling the grid rendering function again ( this.gridOptions.api.refreshView(); ), but it didn't help me.

Muni Chittem

Header names can be assigned dynamically after data binding to the grid in the GridReady event.

this.gridOptionsDetail.api.getColumnDef("params_1").headerName = "Files Count (" + fileCount + )";
this.gridOptionsDetail.api.refreshHeader();

//column def

this.columnDefs = [
                        {
                headerName: "Test Columns",
                field: "test1",
                cellStyle: { 'text-align': 'left' },
                suppressSorting: true,
                minWidth: 250,
                ColId:"params_1"
            }];

params_1 is the column key, not the column name.

Related


Dynamically change headerName ag-grid Angular 2?

Valitskiy Dmitriy I have the following code: public fy: string = "17"; let months = ['July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March', 'April', 'May', 'June',]; function headerCellRendererFunc(year, para

Dynamically change headerName ag-grid Angular 2?

Valitskiy Dmitriy I have the following code: public fy: string = "17"; let months = ['July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March', 'April', 'May', 'June',]; function headerCellRendererFunc(year, para

Dynamically change headerName ag-grid Angular 2?

Valitskiy Dmitriy I have the following code: public fy: string = "17"; let months = ['July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March', 'April', 'May', 'June',]; function headerCellRendererFunc(year, para

Dynamically change headerName ag-grid Angular 2?

Valitskiy Dmitriy I have the following code: public fy: string = "17"; let months = ['July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March', 'April', 'May', 'June',]; function headerCellRendererFunc(year, para

Dynamically change or set cell category in Ag Grid

Nazir Ahmed I have a Div whose size can change based on user actions (small and large views) (only div resizes), and the div contains ag-grid. Initially the div/grid loads in compressed size, so I used classes (small font-size, height, padding, etc.) to remove

Angular-Ag-Grid - Dynamically add columns

Helen In 2 cases, I need to add some columns to Ag-grid. In other cases, I just need the base column. So in the constructor, I declare the grid like this: this.gridOption.columnDefs = [ { headerName: 'Admission date', field: 'admissionPlanned

Angular-Ag-Grid - Dynamically add columns

Helen In 2 cases, I need to add some columns to Ag-grid. In other cases, I just need the base column. So in the constructor, I declare the grid like this: this.gridOption.columnDefs = [ { headerName: 'Admission date', field: 'admissionPlanned

How can I dynamically change the options of ag-Grid?

Matt123 I am creating an ag-grid with the below code. I would like to dynamically change the rowSelection option from single to multiple onClick of a button. <ag-grid-angular #validateGrid style="width: 780px; height: 260px;" class="ag-theme-balham"

Ag-Grid not showing as angular 2?

Umer I am new to angular 2 and trying to configure ag-grid. Error on console about ag-grid. I have solved it. Now there are no other errors on the console except one error, but it has nothing to do with ag-grid. But still no grid is displayed. Here is the code

Ag-Grid not showing as angular 2?

Umer I am new to angular 2 and trying to configure ag-grid. Error on console about ag-grid. I have solved it. Now there are no other errors on the console except one error, but it has nothing to do with ag-grid. But still no grid is displayed. Here is the code

Ag-Grid not showing as angular 2?

Umer I am new to angular 2 and trying to configure ag-grid. Error on console about ag-grid. I have solved it. Now there are no other errors on the console except one error, but it has nothing to do with ag-grid. But still no grid is displayed. Here is the code

Ag-Grid not showing as angular 2?

Umer I am new to angular 2 and trying to configure ag-grid. Error on console about ag-grid. I have solved it. Now there are no other errors on the console except one error, but it has nothing to do with ag-grid. But still no grid is displayed. Here is the code

Ag-Grid not showing as angular 2?

Umer I am new to angular 2 and trying to configure ag-grid. Error on console about ag-grid. I have solved it. Now there are no other errors on the console except one error, but it has nothing to do with ag-grid. But still no grid is displayed. Here is the code

How to dynamically align ag-grid-angular headers

Vikas Nale I have an ag-grid with angular 6 and dynamically appended columns and data. Now I want to align the headers (parent and child in case of multiple headers) dynamically. Like the first column header should be left aligned and other headers should be c

How to dynamically align ag-grid-angular headers

Vikas Nale I have an ag-grid with angular 6 and dynamically appended columns and data. Now I want to align the headers (parent and child in case of multiple headers) dynamically. Like the first column header should be left aligned and other headers should be c

How to dynamically align ag-grid-angular headers

Vikas Nale I have an ag-grid with angular 6 and dynamically appended columns and data. Now I want to align the headers (parent and child in case of multiple headers) dynamically. Like the first column header should be left aligned and other headers should be c

How to dynamically align ag-grid-angular headers

Vikas Nale I have an ag-grid with angular 6 and dynamically appended columns and data. Now I want to align the headers (parent and child in case of multiple headers) dynamically. Like the first column header should be left aligned and other headers should be c

How to dynamically align ag-grid-angular headers

Vikas Nale I have an ag-grid with angular 6 and dynamically appended columns and data. Now I want to align the headers (parent and child in case of multiple headers) dynamically. Like the first column header should be left aligned and other headers should be c

How to dynamically align ag-grid-angular headers

Vikas Nale I have an ag-grid with angular 6 and dynamically appended columns and data. Now I want to align the headers (parent and child in case of multiple headers) dynamically. Like the first column header should be left aligned and other headers should be c

How to add space between two rows ag-grid in Angular 2 ag-grid

Vaibhav Patil The above image is like what I want But I used ag-grid, so my output looks like the image below I am using aggrid. I want more space between the 2 row grids, which indicates that the row is separate. .ag-body-container .ag-row { margin-t

How to add space between two rows ag-grid in Angular 2 ag-grid

Vaibhav Patil The above image is like what I want But I used ag-grid, so my output looks like the image below I am using aggrid. I want more space between the 2 row grids, which indicates that the row is separate. .ag-body-container .ag-row { margin-t