Extra column with buttons in the Angular UI grid (every row button opens in a window component with a summary of the row fields with values)

1 Answer 90 Views
Button Grid Window
Stavros
Top achievements
Rank 1
Iron
Stavros asked on 29 Sep 2021, 03:55 PM | edited on 29 Sep 2021, 03:56 PM

As the topic explains I want to create an extra column (without column header) with buttons that every one of them opens in a kendo ui window component that has all the fields of the same row as the button, with its values as content.

Is it possible?

I am using Kendo UI for Angular

1 Answer, 1 is accepted

Sort by
1
Accepted
Yanmario
Telerik team
answered on 30 Sep 2021, 08:16 AM

Hi Stavros,

Indeed the desired requirement can be achieved with the use of kendoGridCellTemplate and the Window component service. The kendoGridCell template context is set to the current data item that can be passed through a (click) event on button press:

<kendo-grid-column>
        <ng-template kendoGridCellTemplate let-dataItem>
          <button class="k-button" (click)="onClick(dataItem)">ViewInfo</button>
        </ng-template>
</kendo-grid-column>

Then what is left is to call the WindowService -> open method and set the WindowSettings depending on the application requirement:

public onClick(data: any) {
    //Asynchronous source
    if (data.ProductName === undefined) {
      this.windowService.open({
        title: `${data.CategoryName}`,
        content: `${data.CategoryName}:  ${data.Description} , ID: ${
          data.CategoryID
        }`,
        width: 300,
        height: 125
      });
    }
    // Array and GridDataResult
    else {
      this.windowService.open({
        title: `${data.ProductName}`,
        content: `Product Name: ${data.ProductName}, Quantity: ${
          data.QuantityPerUnit
        } , Price: ${data.UnitPrice}`,
        width: 300,
        height: 125
      });
    }
  }

StackBlitz example demonstrating the above approach:

https://stackblitz.com/edit/grid-with-window-component-vycpre

Further adjustments might be required depending on the use case scenario.

I hope this helps and streets you in the right direction.

Regards,
Yanmario
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Stavros
Top achievements
Rank 1
Iron
commented on 30 Sep 2021, 09:19 PM

Cool but how do you insert html code inside this content property?

I tried it and it does not work.

I also can't use


content: template
because the home.component.ts where I want to use it has already an external template file called home.component.html.
Yanmario
Telerik team
commented on 05 Oct 2021, 07:55 AM

Hi Stavros,

The Window component allows the rendering of component types in its content area, as demonstrated in the following article from our documentation:

https://www.telerik.com/kendo-angular-ui-develop/components/dialogs/window/service/#toc-content-component

I hope this helps.

Regards,
Yanmario
Progress Telerik

Tags
Button Grid Window
Asked by
Stavros
Top achievements
Rank 1
Iron
Answers by
Yanmario
Telerik team
Share this question
or