Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overlay control on top of a row in ag-grid?

I have a requirement to add a specific control on top of rows that contain data that matches specific criteria. Those criteria are missing required information that needs to be added with an inline editing feature. What we want is a navigation control that seats on top of the first matching row and that leads you to the next one by clicking on "next", which will make the grid scroll up to the next matching row which will display another control on top and above allowing to navigate to next matching row or go to previous.

So let's say we have a list of cars, and we want the user to navigate over the rows of cars that have a price lower or equals to 45k, you'll see something like:

enter image description here

On the next click you'll see something like:

enter image description here

I believe in order to have this feature, I would need a reference to the rows and inject a component in the DOM relative to each row on click. But I'm not sure how to do that. I've attempted to dynamically add the component to the native element of the first matching row like this:

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

    params.api.forEachNode((node, index) => {
      if(node.data.price <= 45000) {
        this.matchingIndexes.push(index);
      }
    });

    let firstRowRef = this.gridElementRef.nativeElement.querySelectorAll(`[row-index="${this.matchingIndexes[0]}"]`)[1];
    
    const factory = this.factoryResolver.resolveComponentFactory(PagingOverlayComponent)
    const component = factory.create(firstRowRef.parentInjector)
    this.viewContainerRef.insert(component.hostView);
  }

I want to be able to insert the component somehow in relation to the row it has to be attached so I can position it over it. This is the farthest I have been able to go:

enter image description here

Any ideas on how can I achieve this?

Please find a working stackblitz here

like image 687
jacoviza Avatar asked Feb 23 '21 19:02

jacoviza


People also ask

How do you set ag-grid dynamically height?

You can use ag-grid feature AutoHeight = true in the column Configuration. or if you want to calculate the height dynamically you should use getRowHeight() callback and create DOM elements like div and span , and add your text in it, then the div will give the OffsetHeight for it then you wont see any cropping of data/ ...

How do you use setRowData on ag-grid?

Update the Row Data inside the grid by updating the rowData grid property or by calling the grid API setRowData() . The example below shows the data with two sets of data. Clicking the buttons toggles between the data sets.

How do you customize ag-grid pagination?

To create a customised pagination panel, you have to do the following two things: Set suppressPaginationPanel=true to tell the grid to not show the default controls for pagination, as shown in the documentation. Create a Custom Status Bar Panel to design your pagination panel as per your requirements.

How does the grid manage overlays?

The grid manages showing and hiding of the overlays for you, so you may not ever need to call the above API methods. When the table is first initialised, the loading panel is displayed if rowData is set to null or undefined.

What are the overlays for the grid when using client-side data row model?

At present, there are two overlays for the grid when using Client-side Data Row Model: Loading: Gets displayed when the grid is loading data. No Rows: Gets displayed when loading has complete but no rows to show.

What is overlay component in angular data grid?

Angular Data Grid: Overlay Component Overlay components allow you to add your own overlays to AG Grid. Use these when the provided overlays do not meet your requirements. Simple Loading Overlay Component

What are the most common row conditional formatting scenarios in AG grid?

More Actions… Let's now look at the most common row conditional formatting scenarios and how to implement them in AG Grid. This is the most common conditional formatting scenario - you apply a style (for example set the background colour) to a row based on a cell value.


Video Answer


1 Answers

We did something fairly similar to this for an application in our bank, but we are using AdapTable which is a component that sits on top of ag-Grid.

That has a search function which includes an option just to return all result sets. It also has api methods to jump to a cell and highlight a cell. So we created something very similar to this and each time you clicked the arrow we got AdapTable to highlight and jump to the relevant cell in ag-Grid.

It was quite easy to implement - a couple of hours at most - but as I say we used AdapTable and not ag-Grid directly and I don't know what that does internally to return the search result set to us.

like image 66
Henders Avatar answered Oct 17 '22 21:10

Henders