How to add horizontal scroll with pinned columns AG Grid – Angular

  ag-grid, ag-grid-angular, angular, grid

I have multiple columns groups in my Ag-Grid Column Definitions and in them first one static pinned columns and remaining groups will be calculated based on given date, and I want to pinned first column group to left but the thing is it contain 10 number of columns and on pinning left they occupy all of view port, so I hoping someone guide me how to add horizontal scroll on pinned columns or to set max-width of column group to show horizontal scroll.

Here are my Column Definitions:

export const approvalGridColDefs = (startDate) => {
  const approvalGridColDefs = [];
  approvalGridColDefs.push({
    headerName: '',
    children: [
      {
        headerName: 'Internal SKU ID',
        field: 'internalSKUId',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Status',
        field: 'actionName',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Item Description',
        field: 'itemDescription',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Release Date',
        field: 'releaseDate',
        type: 'date',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Account',
        field: 'accountName',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Fixture',
        field: 'fixture',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'UPC',
        field: 'upc',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Class Name',
        field: 'className',
        // hide: true,
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Rating',
        field: 'ratingName',
        pinned: 'left',
        suppressToolPanel: true
      },
      {
        headerName: 'Theatrical Release',
        field: 'theatricalReleaseDate',
        type: 'date',
        pinned: 'left',
        suppressToolPanel: true
      }
    ]
  });
  for (let weekIndex = 1; weekIndex <= 8; weekIndex++) {
    const weekDate = addWeeks(new Date(startDate), weekIndex);
    approvalGridColDefs.push({
      headerName: moment(weekDate).format('MM/DD/YYYY'),
      field: `week${weekIndex}`,
      marryChildren: true,
      headerClass: 'approval-column-group',
      cellStyle: { textAlign: 'center', justifyContent: 'center' },
      children: [
        {
          headerName: 'Promo Price',
          field: `promoPriceWeek${weekIndex}`,
          editable: true,
          cellEditor: 'numericCellEditor',
          headerClass: 'approval-first-header',
          cellStyle: { borderLeft: '2px solid lightgray' }
        },
        {
          headerName: 'Margin Credit',
          field: `marginCreditWeek${weekIndex}`,
          editable: true,
          cellEditor: 'numericCellEditor'
        },
        {
          headerName: 'B&M Promo Week Forecast',
          field: `bAndMPromoForecastWeek${weekIndex}`,
          editable: true,
          cellEditor: 'numericCellEditor'
        },
        {
          headerName: 'Dotcom Week Forecast',
          field: `dotComForecastWeek${weekIndex}`,
          editable: true,
          cellEditor: 'numericCellEditor'
        },
        {
          headerName: 'On Ad',
          field: `onAdWeek${weekIndex}`,
          editable: true,
          cellEditor: 'agSelectCellEditor',
          cellEditorParams: {
            values: extractValues(yesNoMapping)
          },
          filterParams: {
            valueFormatter: function (params) {
              return lookupValue(yesNoMapping, params.value);
            },
          },
          valueFormatter: params => {
            return lookupValue(yesNoMapping, params.value);
          }
        }
      ]
    });
  }
  return approvalGridColDefs;
}

By default no horizontal scroll is visible because pinned columns occupy all of the space and after adjusting the width of individual column here is how the grid is showing:
enter image description here

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.