Stop Ag grid from automatically extending to the entire width of the screen

I am encountering an issue where my table scales to the full width available even when the content is limited.
Take a look at the demo here: "https://plnkr.co/edit/6L8bTAwkEV6R6Be4M1Qm?p=preview"
I have attempted to address this problem by setting a width for the parent element and a max-width for the ag-grid, but as you can see, it has had no effect. Does anyone have any ideas on how to solve this?
Thank you in advance.

Answer №1

To ensure proper grid sizing, utilize the sizeColumnsToFit() method.

sizeColumnsToFit() function automatically adjusts column sizes to fit the grid horizontally.

Official documentation

Sample code:

onGridReady(params) {
    this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    this.gridApi.sizeColumnsToFit();
    ....
}

Check out your updated Plnkr example

Additional note: understanding the sizeColumnsToFit method

Remember that for sizeColumnsToFit() to work correctly, you must define and assign grid columns to the gridOptions property. If looking for a dynamic solution, ensure to set column definitions with setColumnDefs before calling the sizeColumnsToFit method.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Ensure Uniform Visual Border-Radius Across Buttons of Varying Sizes with CSS calc() Function

I’m currently tackling a project that involves the use of two buttons with different sizes. Despite both buttons having the same specified border-radius of 6px, they seem to display differently in the browser. The smaller button appears to have a larger ...

Sending Data to Prestashop API: A Guide for Angular Developers

I've been working on a project using Angular that interacts with the API of Prestashop. Retrieving the list of products is easy because Prestashop provides it in JSON format. Now, I need to create data (POST data) and Prestashop requires XML. They o ...

Using angular in combination with razor for implementing cookie-based authentication

Embarking on a new project with Angular 7, Asp.net core 2, Asp.net Identity, and IdentityServer4. In summary, the architecture of my project is structured as follows: A web API project (resource server) Data access layer project (C# project library) Ide ...

The height of the href is not displaying correctly when the text-decoration is disabled and it is placed next to

In my design, I have a link positioned next to an image with perfect vertical alignment. Everything looks great when the text has the standard text-decoration, centered vertically and all that. However, as soon as I remove the text-decoration, leaving the ...

What factors must be considered before transitioning from an HTML4 web application to HTML5?

As a newer web apps developer, I've created various applications when HTML 5 was on the rise as the new standard. Now, I'm considering migrating some of those apps to HTML 5 and wondering if it's a good idea. Despite my experience in web d ...

Include a class in the html root tag

Is there a way to dynamically add a class to the root HTML tag when a specific button is clicked? Most resources I've found only show how to add classes to div elements with IDs. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

Prevent the bootstrap header in a table from scrolling by enclosing it in

I am encountering an issue with fixing the headers of multiple tables in a page within their dedicated divs. Despite trying various methods, I haven't been successful as the fixed header overflows the div. I want to confine it within the div. Additio ...

Creating a unified deployable package for a Spring Boot Rest service and an Angular App in a single war file

Currently dealing with a scenario where I find myself needing to deploy a single war file containing an Angular application that consumes a REST API also located within the same war file. The issue arises when CORS errors occur while trying to communicate ...

Spring MVC seems to be ignoring the static resources specified in the HTML files

Currently, I am in the process of creating a straightforward Spring MVC (v4.1.2) and Angular4 application. Essentially, this application performs CRUD operations by sending HTTP requests from the Angular client. The following combination works seamlessly ...

Eradicate lines that are empty

I have a list of user roles that I need to display in a dropdown menu: export enum UserRoleType { masterAdmin = 'ROLE_MASTER_ADMIN' merchantAdmin = 'ROLE_MERCHANT_ADMIN' resellerAdmin = 'ROLE_RESELLER_ADMIN' } export c ...

Ensure that the radio button is set to its default option when the user accesses the page

I have a model with a 'PartActionType' enum which includes Transfer, Harvest, and Dispose options. public enum PartActionType { Transfer, Harvest, Dispose } On my view page, I am displaying these options using ...

Beginner experiencing website overflow problem

After completing a basic web development course, I decided to create my first homepage. While I am satisfied with how it looks on a PC or laptop, the layout gets messy on mobile devices. I tried using <meta name="viewport" content="width= ...

Navigating through multiple checkbox values in Angular 4/5

Is there a way to retrieve values from checkboxes other than just true or false? Take a look at my template below: <h4>Categories</h4> <div class="form-check" *ngFor="let cat of categories$|async"> <input class="form-check-input" ...

Querying the height of an image element using jQuery and dynamically adding padding if necessary

I've got a Bootstrap carousel displaying images with different heights, and I'm looking to vertically center these images. My approach involves determining the image height, subtracting it from a fixed height value, and if the result is less than ...

Can you identify the animation being used on this button - is it CSS or JavaScript?

While browsing ThemeForest, I stumbled upon this theme: What caught my eye were the animation effects on the two buttons in the slider ("buy intense now" and "start a journey"). I tried to inspect the code using Firebug but couldn't figure it out com ...

Spontaneous gradient background occasionally failing to load as expected

My to-do list is simple and functional, but I'm encountering an unusual issue with the background. The background is supposed to be a random gradient set using JS upon loading the HTML, but sometimes it doesn't apply at all. If you refresh the Co ...

The text outside of the button is overridden by my CSS styling

I've been working on a simple card matching game and I decided to style the buttons to enhance their appearance. However, I'm facing an issue where the styling code has caused the text to appear outside of the button. Whenever I try to adjust the ...

Implementing File Retrieval in a Controller

I have a specific file where I declared the URL for my videouploadfolder, and now I need to reference that file in my JavaScript config.js. var filepath = { uploadVideoUrl : './public/videos' } In my Node.js script, I included it like th ...

Optimize your website by reducing the size of CSS, JavaScript, and HTML files through NUXT's

I'm currently working on a project in NUXT utilizing yarn for managing packages. My objective is to compress (and potentially merge) js, css, and html files to enhance load time efficiency. I came across "https://www.npmjs.com/package/nuxt-compress" ...

Having trouble opening a materialize modal in Angular 2?

I am facing an issue where the modal does not open when the component loads, and I cannot figure out why. Any assistance would be greatly appreciated. component.html: <div id="modal" class="modal modal-fixed-footer" materialize="modal" [materializeAct ...