Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The default minimum and maximum column width in ag-grid can be established in the following way:

  1. Set the default minimum and maximum column width in the grid options:
var gridOptions = {
    //...
    colMinWidth: 100,
    colMaxWidth: 500
};
  1. If you want to override these values for a specific column, you can set the minWidth and maxWidth properties in the column definition:
var columnDefs = [
    { field: 'athlete', minWidth: 150, maxWidth: 300 },
    { field: 'country' },
    { field: 'year' },
    { field: 'gold' },
    { field: 'silver' },
    { field: 'bronze' }
];
  1. You can also use callbacks to dynamically calculate the minimum and maximum column width based on the content of the cells. For example, you can use the processCellForClipboard callback to calculate the width of the cell content:
var gridOptions = {
    //...
    processCellForClipboard: function(params) {
        var cellWidth = calculateCellWidth(params.value);
        var newParams = { value: params.value, $scope: params.$scope };
        newParams.$scope.$agGridCellWidth = cellWidth;
        return newParams;
    },
    getColWidth: function(params) {
        var cellWidth = params.$scope.$agGridCellWidth;
        return cellWidth + 20; // add some padding
    }
};

function calculateCellWidth(value) {
    // calculate the width of the cell content
}