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 center aligned.

I tried to set cellStyle and other options I found but none of them work

I tried to implement it like this:

  let headerItem = {
    headerName: name,
    children: [
      {
        headerName: name,
        field: 'col' + i + '.value',
        hide: isHidden,
        pinned: pinned,
        cellStyle: function (params) {
          try {
            return {text-align : 'center'};
          } catch (e) {
            return null;
          }
        }
      }
    ],
    cellStyle: function (params) {
          try {
            return {text-align : 'center'};
          } catch (e) {
            return null;
          }
        }
  }

Please guide me how to make it work...

wentjun

Assuming you are using the latest version of Ag-Grid (if not), if we want to make any customizations to the header cells , we have to create a custom cell header component .

I used an existing Ag-grid example and created a demo for you . (See app/custom-header.component.ts for custom header templates)

What I did is created a separate component for it and set the template for the header to the following to align it both vertically and horizontally (I'm using CSS flexbox properties for this)

<div style="display:flex;justify-content:center;align-items:center;">
  {{params.displayName}}
</div>

Related


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 wrap column headers in ag-grid using angular

UI_Dev I have columns that have four words, pre-trade follow up, post-trade follow up, and some of them have three words. I tried the following CSS to wrap the text into multiple lines. ::ng-deep .ag-theme-material .ag-header-cell-label .ag-header-cell-text{

How to wrap column headers in ag-grid using angular

UI_Dev I have columns that have four words, pre-trade follow up, post-trade follow up, and some of them have three words. I tried the following CSS to wrap the text into multiple lines. ::ng-deep .ag-theme-material .ag-header-cell-label .ag-header-cell-text{

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 to align Angular grid in CSS?

User 10766540 How to align grid in center of page using css in Angular component .grid-container { display: grid; grid-gap: 20px; grid-template-columns: repeat(3, 1fr); } I tried margin-left and margin-right percentages, but it didn't work very well. <mai

How to align Angular grid in CSS?

User 10766540 How to align grid in center of page using css in Angular component .grid-container { display: grid; grid-gap: 20px; grid-template-columns: repeat(3, 1fr); } I tried margin-left and margin-right percentages, but it didn't work very well. <mai

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 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

How to embed dropDown HTML into ag-grid column headers?

Sumi Kanduli Below is a snapshot of the ag-Grid and Kendo grid. My question is, how to embed dropdown/html into ag-Grid like in kendo. I tried binding it with headerCellTemplate but it removes the columnName header from the grid and overwrites it with dropDown

How to enable sorting in angular ag grid

Slobber I'm trying to add sorting to a simple ag grid, but I keep getting the error: Cannot bind to 'enableSorting' because it's not a known property of 'ag-grid-angular'. Here is the template: <ag-grid-angular [enableSorting]="true" [rowData]="rowData" [co

How to trigger firstDataRendered on ag-grid in angular?

Alex Koretsky My component has an input that gets data, and I use firstDataRendered to select the first row. The problem is that the grid doesn't fire the event when the input data changes how can I fire the grid event based on my input change? <ag-grid-angul

How to use Ag-Grid in Angular 11

eight times Is it possible to use Ag-Grid enterprise/community edition in Angular 11 I am using angular 11 in my application but I am not getting any hint from anywhere that Angular 11 supports enterprise edition of AG-GRID PKS9906 possible. Here is a link to

How to dynamically add custom columns in Ag-Grid

shivek parmar I am stacking to dynamically add custom columns in ag-grid. I have tried the following methods. additionalCol = { field:'SOME RANDOM', headerName: 'SOME RANDOM' }; $scope.gridOptions.columnApi.addValueColumn(additionalCol); I also tried $scope.c

How to dynamically add row styles? -Ag-grid

knowledge I want to dynamically change the style of rows in ag-grid. What I'm trying to achieve is that if the user has edited the background color of the ag-grid row, the row changes. cellValueChanged(event) { //Add it only if the old value has changed if

How to dynamically add custom columns in Ag-Grid

shivek parmar I am stacking to dynamically add custom columns in ag-grid. I have tried the following methods. additionalCol = { field:'SOME RANDOM', headerName: 'SOME RANDOM' }; $scope.gridOptions.columnApi.addValueColumn(additionalCol); I also tried $scope.c

How to dynamically add custom columns in Ag-Grid

Shivek Parma I am stacking to dynamically add "custom" columns in ag-grid. I have tried the following methods. additionalCol = { field:'SOME RANDOM', headerName: 'SOME RANDOM' }; $scope.gridOptions.columnApi.addValueColumn(additionalCol); I also tried $scope.

How to dynamically add custom columns in Ag-Grid

Shivek Parma I am stacking to dynamically add "custom" columns in ag-grid. I have tried the following methods. additionalCol = { field:'SOME RANDOM', headerName: 'SOME RANDOM' }; $scope.gridOptions.columnApi.addValueColumn(additionalCol); I also tried $scope.

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"

How to dynamically add custom columns in Ag-Grid

shivek parmar I am stacking to dynamically add custom columns in ag-grid. I have tried the following methods. additionalCol = { field:'SOME RANDOM', headerName: 'SOME RANDOM' }; $scope.gridOptions.columnApi.addValueColumn(additionalCol); I also tried $scope.c