Send the template to the enclosed grid column

I enclosed a kendo-grid-column within a new component by using

<imx-gridColumn field="Count" title="Count">
...
</imx-gridColumn>

The component that includes the imx-gridColumn is templated with

<kendo-grid-column #column field="{{field}}">
...
</kendo-grid-column>

Everything seems to be working smoothly. Now I want to do something like

<imx-gridColumn field="Message" title="A longer message">
    <ng-template kendoGridCellTemplate let-dataItem>
        <button (click)="ShowMessage(dataItem)">Show my message</button>
    </ng-template>
</imx-gridColumn>

in order to apply a template specifically to this column. Other columns should use the standard template provided by the kendo-grid-column.

Is there a straightforward way to pass the ng-template to the kendo-grid-column? If not, how can I modify the content of the column so that the button is used instead of plain text?

Edit
After some investigation, I managed to extract the template using

@ContentChild(TemplateRef) Template:TemplateRef<ElementRef>
, which at least contains some data. But now I'm struggling with pushing this template to my kendo-grid-column.

Answer №1

At long last, I have found the solution to this challenging issue and feel compelled to share it with others who may find themselves in a similar predicament.
I will only be disclosing the essential parts of the solution, not the complete files.

GridColumn.component.ts

@Component({
    selector: 'imx-gridColumn',
    templateUrl: './GridColumn.component.html',
})

export class imx_GridColumnComponent
{
  ...
  @ContentChild('kendoGridCellTemplate') Template:TemplateRef<ElementRef>;
}

GridColumn.component.html

<kendo-grid-column field="{{field}}">
   ...
    <ng-template *ngIf="Template" kendoGridCellTemplate let-dataItem>
         <ng-container [ngTemplateOutlet]="Template" [ngTemplateOutletContext]="{$implicit:dataItem}"></ng-container>
    </ng-template>
</kendo-grid-column>

Once done, you can easily pass the template to the grid column using the following method:

<imx-gridColumn field="Message" title="A longer message">
    <ng-template #kendoGridCellTemplate let-dataItem>
        <button (click)="ShowMessage(dataItem)">Show my message</button>
    </ng-template>
</imx-gridColumn>

Please note that if you wish to provide multiple templates, you must assign an identifier to ensure the correct template is applied. I opted to use the same naming convention as Kendo for their directives, simply adding a "#" prefix, but you are free to choose any name you prefer.

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

Vue's computed property utilizing typed variables

I am trying to create a computed array of type Todo[], but I keep encountering this specific error: No overload matches this call. Overload 1 of 2, '(getter: ComputedGetter<Todo[]>, debugOptions?: DebuggerOptions | undefined): ComputedRef<T ...

How can I prevent the installation of my Ionic 2 application on devices that have been rooted or jailbroken?

I am currently working on a project involving an Ionic 2 and Angular 2 application. I need to implement a feature that checks whether the device is rooted (in the case of Android) or jailbroken (in the case of iOS). I have experimented with various packag ...

Adding custom TypeScript classes to an Electron project is a straightforward process that allows developers to enhance their

Currently working on a hello world project in Electron and stumbled across the possibility of using Typescript for the Main process, . The provided instructions suggest changing the file extension from index.js to index.ts and updating the package.json fi ...

What specific type of useRef should I use to reference a callback function?

I have been exploring the method outlined by Dan Abramov for creating a custom hook to handle basic setInterval functionality. However, I am facing challenges while trying to type it in TypeScript. Specifically, I am unsure about what should be the type of ...

Guidelines for automatically exporting (and downloading) a Highcharts chart created in Angular

I've been working on an Angular project where I successfully created a chart using the Highcharts library and the Angular-Highcharts package. The chart looks great, but now I'm facing an issue with automatically exporting it using the Highcharts ...

Is it possible to import a module that was exported in Node.js using the SystemJS import method?

When working on a Node project, we typically import modules using the require keyword. Is it possible to import the same module in an Angular 2 project using import {} from '', even if the d.ts file is not available? For instance, can I incorpora ...

Mastering the Art of Sharing PrimgNg Selected Checkboxes with Child Component Dropdown

I am developing a simple application using PrimeNg. In order to pass information from the selected items of a Multi-Select component in the parent element (<p-multiSelect/>) to a Dropdown component in the child element (<p-dropdown/>), I have i ...

Typescript: Ways to fix the error 'rxjs/Rx does not have any exported member 'SubscriptionLike'

I'm attempting to replicate the steps outlined in this tutorial found here https://www.youtube.com/watch?v=gxCu5TEmxXE. However, upon running tsc -p, I encounter an error. Is there a specific import that I am missing? ERROR: node_modules/@angular/co ...

I am interested in creating a versatile validation system that can be applied to any Angular form. The standard reactive approach is already completed and functioning effectively

I am looking for a way to implement generic validation in Angular forms that can be used across different components. The basic reactive form is already set up and running smoothly, but I need assistance with implementing a more versatile approach. Can a ...

Defining a structure for an entity in which its attributes distinguish between different data types and an array combination

I strongly believe that the best way to showcase this concept is through a clear example: enum EventType { A, B, C }; type MyEvent = [EventType.A, number] | [EventType.B, string] | [EventType.C, number, string]; const eventsGrouped: Record<Event ...

Learn the ins and outs of utilizing *ngIf in index.html within Angular 8

Can anyone explain how I can implement the *ngIf condition in index.html for Angular2+? I need to dynamically load tags based on a condition using the *ngIf directive, and I'm trying to retrieve the value from local storage. Below is my code snippet b ...

Changing the default font size has no effect on ChartJS

I'm trying to customize the font size for a chart by changing the default value from 40px to 14px. However, when I set Chart.defaults.global.defaultFontSize to 14, the changes don't seem to take effect. Below is the code snippet for reference. An ...

Storing a child in an existing object with Firebase and Angular 6

How can I save a new form to an existing list with the following code snippet: createNewTumeur(newTumeur: Tumeur) { this.tumeurs.push(newTumeur); const id: string = this.route.snapshot.params['id']; firebase. ...

Is it feasible to arrange tables in ng-bootstrap Sortable Tables by default column selection?

Currently, I am in the process of developing an Angular project that utilizes the ng-bootstrap Sortable Table component. This particular component can be found at the following link: My issue lies in the fact that I require the table to automatically sort ...

What is the best way to access data in a node.js application from IONIC typescript via a REST API?

Here is the structure of my service.ts: import { Injectable } from '@angular/core'; import {Http, Headers} from '@angular/http'; import 'rxjs/add/operator/map'; /* Generated class for the PeopleSearch provider. See http ...

Implement a universal Custom Validator to be applied to all FormControls across the entire application

We've encountered a scenario where a client proposed incorporating a custom validator to every field in their application, which comprises of over 1000 Angular formControls. I'm curious to know if there exists a method to universally alter the f ...

Strategies for modifying the title attribute within an <a> tag upon Angular click event

I am attempting to dynamically change the title attribute within an anchor tag upon clicking it. The goal is for the title attribute to toggle between two states each time it is clicked. Currently, I am able to change the title attribute successfully upon ...

Change the type of an object to a different type

Within my class, I have set the type of range to IntervalRange. export class Test {range: IntervalRange;} Then, in the parent class, I initialize the value: export class TestInitializer { Create(){ return <Test>{ range: IntervalRange.i ...

What could be causing the profile detail to be missing in the home component?

To optimize performance, I am trying to only call the profile API if there is no detail available. This way, the API will only be called when necessary, such as when the user first visits the home component. I am using route resolve to ensure that the data ...

The getStaticProps() method in NextJS does not get invoked when there is a change in

I have integrated my front-end web app with Contentful CMS to retrieve information about various products. As part of my directory setup, the specific configuration is located at /pages/[category]/items/[id]. Within the /pages/[category] directory, you w ...