Is there a method available to calculate the quantity of columns in an angular grid?

I need to customize my angular grid to limit the number of columns displayed on screen to a maximum of 5 at a time. Even if there are more than 5 columns available, I want to restrict the user from showing more than 5. Is it possible to achieve this by setting up a select menu that allows me to switch between viewing only 2 columns at a time? Can this be accomplished using filtering or some JavaScript/TypeScript function?

html

<div>
  <ag-grid-angular style="width: 100%; height: 500px;" class="ag-theme-alpine" [rowData]= "rowData"
    [columnDefs]= "columnDefs" >
  </ag-grid-angular>
</div>

component

import { Component } from '@angular/core';
import { GridRes } from './gridres.model';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'ag-custom';


  columnDefs = [
    {headerName: "Make", field: "make"},
    {headerName: "Model", field: "model"},
    {headerName: "Price", field: "price"}
];

rowData = [
  {make: "Toyota", model: "Celica", price: 35000},
  {make: "Ford", model: "Mondeo", price: 32000},
  {make: "Porsche", model: "Boxter", price: 72000}
];

}

Answer №1

AG Grid triggers an event every time a column becomes visible:

Events.EVENT_COLUMN_VISIBLE

To optimize your display, consider subscribing to this event and monitoring the number of visible columns. If more than 2 columns are visible, you can dynamically swap out one of the existing columns with the new one specified in the event parameters.

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

Attempting to deploy an Angular 9 web project within Visual Studio

Starting my first Angular project has been a smooth process so far. After successfully running "npm start" without any errors, I encountered some issues when launching the application from Visual Studio. Despite sending the same commands, I consistently ...

Guide on setting up a chart using data fetched from an API?

I'm looking to incorporate ngx-charts into my project, but I'm struggling with initializing the chart with data retrieved from my API. Setting up a vertical bar chart seems straightforward. The data structure I have is like this: https://stackb ...

React js Multiselect Component [object Object], [object Object]

I am using Material UI to create a multiple Select component. Below is the code I have written: <TextField classes={{ root: classes.root }} select name="states" id="states" fullWidth ...

"Troubleshooting Angular Reactive Forms: Issue with Dropdown Displaying Incorrect Selected Value

Currently, I'm in the process of constructing a Reactive form using Angular 9 which involves incorporating a dropdown. The code snippet below illustrates the dropdown component: <form [formGroup]="registerForm" (ngSubmit)="onSubmit()"> ... ...

Exploring the Power of Vue.js 3.0: Leveraging Two-Way Data Binding Through the Composition

Currently, I am delving into creating a Vue.js application with Vue.js 3.0 to get acquainted with the Composition API. The simplicity of two-way data-binding in Vue.js 2.0 was one of its standout features for me. However, transitioning to the Composition A ...

The Array.sort method is limited to sorting based on a single criterion

I'm attempting to sort items first by their values and then alphabetically if they have the same value. function order(a, b, total) { if (total == 0) { return a.localeCompare(b) } else { return total; } } var thingsArr = { ...

What is the best way to display a form within every row of a data table?

I am currently working on a page that retrieves data from a backend and displays it in a Datatable. One of the columns in my table is an input field with a default value fetched from the backend, and another column contains buttons. How can I implement a f ...

Is the code failing to refresh the browser when the file is modified?

Does anyone know how to reload the browser when a file changes? var changing = require('changing'); var watcher = changing( { interval: '0s' }); watcher.add("/home/diegonode/Desktop/ExpressCart-master/routes/2.mk"); watcher.on(& ...

Tips on choosing vml elements using jquery or vanilla javascript

I am trying to select a VML element using jQuery without relying on 'id' or 'class', but my attempts have been unsuccessful so far. <v:oval id="vmlElement" style='width:100pt;height:75pt' fillcolor="red"> </v:oval> ...

Typescript challenge: Implementing a route render attribute in React with TypeScript

My component has props named project which are passed through a Link to a Route. Here's how it looks (the project object goes in the state extended property): <Link to={{ pathname: path, state: { project, }, }} key={project. ...

REST API for Azure speech to text (RECOGNIZED: No text detected)

I am currently experimenting with the Azure API for speech to text conversion. However, I am facing an issue where executing the code does not produce any audio result even though the input is in the correct .WAV format. Here's a snippet of the code ...

Transmitting information following successful password verification

Currently, I am working on a form to insert users into a database. Along with this, I have two scripts in place - one for password validation and the other for AJAX retrieval of PHP results. As of now, these two scripts are functioning independently. How ...

Yarn Plug'n'Play was unable to locate the module during the next build

Currently, I am in the process of developing a Next.js project with yarn's Plug'n'Play feature. In this project, I have created several pages and added various packages, including mathjs: '^10.3.0' to assist me in parsing user inpu ...

Exploring the connections among nodes in a Force-Directed Graph using D3.js JavaScript

I am currently working on a complex graph that consists of around 150 nodes using D3 Javascript. The concept behind it is quite intriguing: Each node is interconnected with 100 other nodes. Out of these 100 nodes, 49 are further linked to another set of ...

Guide for toggling two mutually exclusive radio buttons in HTML

I am facing an issue with two radio buttons. My goal is to have one radio button checked while the other becomes unchecked when clicked, and vice versa. Unfortunately, the code I have written so far is not achieving this: <input type="radio" ...

When attempting to import functions from the firebase or @angular/fire libraries in Visual Studio Code, I am not receiving any suggestions from the IDE

I am facing an issue with initializing my Firebase app and using its features in my Angular app. Despite installing all the necessary packages using npm install firebase @angular/fire, I am not receiving any suggestions from the IDE. It seems like the pack ...

Loop through a JSON-formatted string

I am currently faced with the challenge of passing the MongoDB Query Result in String Format to a JSP Page using Ajax. While I am able to successfully retrieve the data, I am struggling with how to iterate over that data. Note : The JSON Structure has a D ...

Maintaining a consistent distance from the baseline while adjusting the font size dynamically in an HTML text element

Looking to lock a text element to the baseline while also resizing its font dynamically when the window is resized. I created a demonstration on jsfiddle. However, the issue arises when the window size changes; the distance from the bottom of the window i ...

How to Dynamically Determine if a Value Matches a Union Type in Typescript

After creating a Union type of supported methods, the goal is to verify if a specific method belongs to the set of supported methods and then execute it dynamically. One commonly used approach is to use an array containing the names of the supported method ...

How to prevent collapse when selecting a node in React.js Mui Treeview

Is there a way to prevent the Treeview from collapsing every time a node is selected? I want it to render a button based on the selected node. Here's an example that I've created: https://codesandbox.io/s/summer-water-33fe7?file=/src/App.js ...