Hello,
I have a hierarchical grid that’s dynamically generated and I want to turn one of the fields of the child list into a hyperlink or button that will open a new window containing more information that the one that's already displayed on the grid.
I’ve been following you documentation: https://ej2.syncfusion.com/16.1.37/documentation/grid/how-to.html?lang=typescript#render-other-components-in-a-column. And I’ve managed to make the link (or button) appear but the column’s field property no longer works correctly (i.e. the content is the one that I placed in the ‘a’ tag of the template which is static).
This is my code:
HTML:
<ejs-grid #grid [dataSource]='requestList' [childGrid]='childList'
height='800px' id="grid" *ngIf="requestList && childList">
<e-columns> ... </e-columns>
</ejs-grid>
TypeScript:
public childList: GridModel = {
dataSource: this.listaValoresPedidos,
queryString: 'NumIntPedido',
allowPaging: true,
pageSettings: { pageSize: 6 },
columns: [
{ field: 'Referencia', headerText: 'Referencia del pedido', width: 120 },
{
headerText: 'Detalles del articulo',
field: 'Descripcion',
template:
`<div style="text-align: center;">
<a rel='nofollow' href="google.com">
test <!--I want to replace the previous word "test" with the content of the "field: 'Descripcion' "-->
</a>
</div>`,
width: 80
},
{ field: 'CantidadPedida', headerText: 'Cantidad Pedida', width: 90 },
//More fields...
]
};
And once it's rendered, the grid field only says "test" in every row.
My main question is: is there a way of introducing the link while maintaining the dynamic aspect of the field?
Also is there a way of binding the new mini template to my original Typescript file? I'm thinking of trying to insert a whole subcomponent instead of just a template, that way I could inherit those functions from one component to the other... But maybe that's not possible and/or there's just a better/simpler way of binding those two things...
Thanks in advance for your help!
| @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { public pData: Object[]; public childGrid: GridModel = { dataSource: orderDatas, queryString: 'EmployeeID', columns: [ { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 }, { field: 'CustomerID', headerText: 'Customer ID', template: '#template', width: 150 }, . . . ], }; ngOnInit(): void { this.pData = employeeData; } } |
| <script id="template" type="text/x-template"> <a rel='nofollow' href="google.com"> ${CustomerID} </a> </script> |
| <ejs-grid #grid [dataSource]='data' (detailDataBound)='bound($event)' id='Grid'> <ng-template #detailTemplate let-data> <div id='Child'></div> </ng-template> <e-columns> . . . </e-columns> </ejs-grid> |
| @Component({ selector: 'control-content', templateUrl: 'detailtemplate.html', styleUrls: ['detailtemplate.style.css'], encapsulation: ViewEncapsulation.None }) export class DetailTemplateComponent implements OnInit { public data: any; ngOnInit(): void { this.data = employeeData; } bound(e){ //Here you can replace the assign the subcomponent to the grid and append it to the detail template. let grid: Grid = subcomponent. grid.appendTo('#Child'); } } } |
Thank you for you reply,
Regarding the first query, I’ve copied your example, I changed the data to call my variables, but now it doesn’t show my child list, it only shows “No records to display” in every single row.
I tried your solution to my second question and it worked.
Thanks for your support Pavithra S. !
| this.childGrid = { dataSource: orderDatas, queryString: 'EmployeeID', allowPaging: true, pageSettings: {pageSize: 6, pageCount: 5}, columns: [ . . . { field: 'ShipCity', headerText: 'Ship City', template:'<a rel='nofollow' href="www.syncfusion.com">${ShipCity}</a>' width: 120 }, . . . ], childGrid: this.secondChildGrid }; |