Utilizing group by date feature in Angular ag-Grid

I'm working on setting up an ag-grid with columns for date, time, and location.

Below is the code snippet:

list.component.ts

columnDefs: any = [{
    headerName: 'Date',
    field: 'date',
    valueFormatter: (data: any) => {
      let date = new Date(data.value);
      const month = date.getMonth;
      return data.value ? month : '';
    },
    rowGroup: true,
    hide: true
  },
  {
    headerName: 'Time',
    field: 'date',
    valueFormatter: (data: any) => {
      return data.value ? (format(data.value, 'hh:mm:ss a')) : '';
    },
  },
  {
    headerName: 'Location',
    field: 'sensor'
  }
]

Is there a way to group the data based on the date column?

Thanks in advance.

Answer №1

columnDefs: any = [{
    headerName: 'Date',
    field: 'date',
    valueFormatter: (data: any) => {
      let date = new Date(data.value);
      const month = date.getMonth;
      return data.value ? month : '';
    },
    rowGroup: true,
    hide: true
  },
  {
    headerName: 'Time',
    field: 'date',
    valueFormatter: (data: any) => {
      return data.value ? (format(data.value, 'hh:mm:ss a')) : '';
    },
  },
  {
    headerName: 'Location',
    field: 'sensor'
  }
]

Answer №2

If you're looking to improve your sorting and grouping capabilities in list.component.ts, here's a handy snippet of code for you:

onGridReady(params: GridReadyEvent) {
   this.gridApi = params.api;
   this.gridColumnApi = params.columnApi;
   this.gridColumnApi.getColumn('date').setSort('asc');
}

This code specifically targets sorting by date, so it may be useful if that's what you're aiming to achieve.

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

Obtain the date in the following format: 2016-01-01T00:00:00.000-00:00

Can someone help me convert this date to the correct format for the mercadolibre api? I need it to be like this: 2016-01-01T00:00:00.000-00:00 However, when I try with the following code: var date_from = new Date(); date_from.setDate(date_from.getDa ...

Change the class of each item in a list individually by hovering over them with the mouse using JavaScript

How to toggle classes in a list item one by one using the mouseover event in JavaScript? const items = document.querySelectorAll("ul li"); let currentItem; for (const item of items) { item.addEventListener("mouseover", e => { currentItem &am ...

Troubleshooting directive not functioning properly with AngularJS ng-click

My HTML img tag is not responding to ng-click when clicked. I'm puzzled by this issue occurring in masonryPictureView.html Main page - home.html <ng-masonry> <ng-picture ng-items="projectdescription.pictures"></ng-picture> </n ...

The content within the mat-card-content paragraph exceeds the boundaries of the mat-card container,

I recently began working with Angular Material and came across an issue. When I have a shorter text paragraph, it overflows the card. However, when I use a larger paragraph, the text wraps nicely. Here is the code snippet: <mat-card *ngFor="let s ...

What is the best way to display circles (generated from JSON data) in reverse order by incorporating a delay function?

I am currently working on creating an interactive visualization using circles that expand over a specified period, all centered at the same point. I have a script that generates these circles and saves the data in a JSON file. The smallest circle is posit ...

Implementing X.PagedList within a modal pop-up window

I have implemented a modal pop-up on a webpage: ... <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="companySearchModal" aria-hidden="true" id="companySearchModal"> <div class="modal-dialog" role="document"> ...

Receive AJAX aid for PHP/MySQL dynamic dropdown menu implementation

My goal is to dynamically populate a second drop-down menu based on the selection made in the first drop-down. The first drop-down contains a list of tables from my database, and the second drop-down should display providers associated with the selected ta ...

Accessing data from a live database in a randomized sequence

When retrieving items from a database, there is often a common code pattern that looks like this: const [dataRcdArray, setDataRcdArray] = useState<never[]>([]); ..... snapshot.forEach((child:IteratedDataSnapshot) => { setDataRcdArray(arr ...

Invalidating the express response object due to a TypeError issue

Currently, I am in the process of writing a test that utilizes sinon and sinon-express-mock to mock an incorrect request. The goal is to then call a validation function within my application and verify that it returns the expected response status code (400 ...

I need a way to call a function in my Typescript code that will update the total value

I am trying to update my total automatically when the quantity or price changes, but so far nothing is happening. The products in question are as follows: this.products = this.ps.getProduct(); this.form= this.fb.group({ 'total': ...

Javascript: What is the best way to narrow down search results using multiple values, regardless of the sequence in which they are entered?

React: How can I improve search result filtering to accommodate multiple values (irrespective of word order)? Example: I want to search for the title of a document using variations like "phone repair process," "repair phone process," or "process phone repa ...

What is the process for creating and registering custom Handlebars functions?

Despite spending plenty of time searching, I am still unable to find detailed information on where exactly to place my custom handlebars helpers. Should they be added in a <script> tag within my webpage's .hbs file? Or should I include them in a ...

Ways to resolve the array to string conversion issue in PHP

In my PHP project, I am dealing with a dynamic array and trying to store the array result in a variable. However, I encountered an error: array to string conversion while coding. <?php require_once('ag.php'); class H { var $Voltage; ...

Retrieving a single object from an array in node.js utilizing elemMatch

My goal is to extract a single object from an array of objects in a data collection using elemMatch. Here is the sample data: [ { "_id": "5ba10e24e1e9f4062801ddeb", "user": { "_id": "5b9b9097650c3414ac96bacc", "firstName": "blah", ...

The switchMap function is sending back a single item

I'm having an issue with switching the observable using the switchMap operator: return this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, { query: { orderByChild: 'deleted', equalTo: false } }) .ma ...

Gathering information from various web pages simultaneously without the need to manually navigate through each page using a webdriver

I'm new to the world of web scraping and I've successfully developed a program that allows me to extract specific, dynamic data by utilizing the selenium web driver. My current project involves scraping data from a FAQ page in order to gather in ...

Why is the click function being invoked twice, but exclusively on the initial click?

In my current project, I am facing an issue with the onClick action that is being passed down from Context. Strangely, when this action is clicked for the first time, it fires twice. However, from the second click onwards, it functions normally and only fi ...

The issue of "Angular library throwing an error outside the specified 'rootDir' directory" arises while attempting to share dependencies

I've been hearing a lot about being able to utilize modules, components, and interfaces in an Angular library. However, I'm constantly encountering an error that says outside of the configured 'rootDir'. projects - app - lib - c ...

Scraping multiple websites using NodeJS

I have been immersing myself in learning NodeJS and experimenting with web scraping a fan wikia to extract character names and save them in a json file. I currently have an array of character names that I want to iterate through, visiting each URL in the a ...

Refreshing a webpage to accurately display changes made in a CRUD application without the need for a hard reset

My to-do app is almost fully functional - I can create items, mark them as completed, and delete them using a delete button. However, there's one issue: when I delete an item, the page doesn't update in real-time. I have to manually refresh the p ...