Hi,
I am trying to use a row details template for the grid control (as described in https://help.syncfusion.com/angular/grid/row#details-template). Everything works as described, but in my actual application, I ran into two problems:
I already tried to switch the template script media type from "text/x-jsrender" to "text/ng-template" (as suggested in some other forum entries) but this seems to not work (I get an "cannot find property __viewRef" exception when trying to expand the detail, similar to a completely missing template)...
Could you please give me a hint to point me into the right direction or can you maybe provide a sample?
Thanks and best regards!
gridComponent.html
<ej-grid [allowPaging]="true" [pageSettings.pageSize]="pagesize" [dataSource]="gridData">
<e-columns>
<e-column field="EmployeeID" headerText="Employee ID" width="90" textAlign="right"></e-column>
<e-column field="FirstName" headerText="First Name" width="90"></e-column>
<e-column field="LastName" headerText="Last Name" width="90"></e-column>
<e-column field="Country" headerText="Country" width="90"></e-column>
</e-columns>
<ng-template e-dtemplate>
<div class="test"></div>
</ng-template>
</ej-grid>
ej.grid.detail-template.ts
ngOnInit() {
var template = this.viewContainerRef.createEmbeddedView(this.templateRef, { '$implicit': [] });
var templID = ej.getGuid('angulartmplstr');
var tempEle = ej.buildTag('div#' + templID);
$(tempEle).append(template.rootNodes);
ej.createObject('detailsTemplate', $($(tempEle).append(template.rootNodes)).html(), this.parent);
this.parent.model.detailsTemplate = $($(tempEle).append(template.rootNodes)).html();
ej.createObject('_templateRef', this.templateRef, this.parent);
ej.createObject('_viewRef', this.viewContainerRef, this.parent);
let old = ej.template['text/x-template'];
var p = this.parent;
ej.template['text/x-template'] = function (self, selector, data, index, prop) {
return old(self, selector, data, index, prop || p);
};
ej.template.render = ej.template['text/x-template'];
$(tempEle).remove();
} |
Hi Jayaprakash,
thanks for your feedback - that is actually more than I expected :-). One more question though: How do I get access to the detail data in the template?
I try do do something like:
Thanks and best regards!
Grid.componenet.html
<ej-grid [allowPaging]="true" [pageSettings.pageSize]="pagesize" [dataSource]="gridData">
<e-columns>
<e-column field="EmployeeID" [isPrimaryKey]="true" headerText="Employee ID" width="90" textAlign="right"></e-column>
<e-column field="FirstName" headerText="First Name" width="90"></e-column>
</e-columns>
<ng-template e-dtemplate let-data>
<div class="test">
<input ej-button [text]='data.FirstName'/>
</div>
</ng-template>
</ej-grid>
Grid.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'ej-app',
templateUrl: 'src/grid/grid.component.html',
})
export class GridComponent {
public gridData: any;
public pagesize: number;
constructor() {
this.gridData = window.employeeView;
this.pagesize = 5;
}
}
|
Hi Farvee,
thanks for providing a sample - however, this does not work (please see the attached screenshot). The input element does not display the Firstname, it is always empty. The debugger shows an exception when trying to expland a row, which seems to be related to the "data" variable not being initialized (see attached screenshot, too). Based on your sample, I only did npm install && npm start, nothing else.
I also looked through the sources and checked to see if I can fix - but without success. The main point which is unclear to me is how the "data" variable is initialized and passed (which is then used by the <ng-template let-data> attribute). Could you please explain?
Thanks!
Hi Seeni Sakthi Kumar,
in the meantime: is there really no workaround getting databinding to work in the detail template (at least Farveen sent out a sample demonstrating this)? I would like to demonstrate this to a customer, so it would be really nice to have this working, even if it is a not so clean solution...
ej.grid.detail-template.ts
export class EJ_Grid_RowTemplate extends EJTemplateDirective {
public parent: GridComponent;
. . .
. .
ngOnInit() {
. . .
. . .
ej.template['text/x-template'] = function (self, selector, data, index, prop) {
return old(self, selector, data, index, prop || p);
};
ej.template.render = ej.template['text/x-template'];
$(tempEle).remove();
}
}
import { EJ_Grid_DetailTemplate } from './gridtemplates/ej.grid.detail-template';
import { Component } from '@angular/core';
@Component({
selector: 'ej-app',
templateUrl: 'src/grid/grid.component.html',
})
export class GridComponent {
public gridData: any;
.. .
. .
}
<ej-grid [allowpaging]="true" [datasource]="gridData">
. .
. .
<ng-template e-dtemplate let-data>
<div class="test">
<input type="text" [value]='data.FirstName' />
</div>
</ng-template>
</ej-grid>
|
Hi,
thank you very much for the updated sample - it is now working as expected. However, I still do not understand how databinding works, so could you please explain it a bit more thoroughly - especially the "let-data" bit - is this name a "magic" name or where does the detail data mapping between the grids dataSource and the item template actually occur?
I searched through your sources to find any instance where the "data" object (which obviously is the detail item data) is initialized. If I understand correctly, "data" gets injected through the template constructor (in ej.grid.detail-template.ts EJ_Grid_DetailTemplate::ngOnInit() where ej.template['text/x-template'] = function(..., data, ...) {};). However, I could not find the place, where it actually get instantiated (so I could see/debug) and how the "[dataSource]=gridData" grid items are assigned to the "data" object for the template?
If I try to replicate this in my application, the "data" object is still not initialized, so I cannot access it in my template and I seem to get the same error/exception as with your previous sample. Any ideas?
ngOnInit() {
var template = this.viewContainerRef.createEmbeddedView(this.templateRef, { '$implicit': [] });
var templID = ej.getGuid('angulartmplstr');
var tempEle = ej.buildTag('div#' + templID);
. .
. . .
let old = ej.template['text/x-template'];
var p = this.parent;
ej.template['text/x-template'] = function (self, selector, data, index, prop) {
return old(self, selector, data, index, prop || p);
};
ej.template.render = ej.template['text/x-template'];
$(tempEle).remove();
} |
Hi,
I seem to be using version 15.2.43 (at least that is the version under node_modules), so I think this should be good?
Attached is another screenshot ("screenshot1") from my environment - you can see the debugger stopping inside the ej.template['text/x-template'] constructor, showing the correct "data" parameter being passed (my detail data items are of type "Mstkn", so this is perfect). However, if I continue running, I get an exception again (screenshot2, screenshot3) - in the detail html template it can obviously not correctly access the data.torqueSeq property (although this is correctly passed as seen on screenshot1).
I don't think there is a lot missing - maybe only a small typo somewhere...
Any Ideas? What else could I check?
Would it make sense to upload my project for you to take a look?
Best regards!
Hi,
I see that there is V15.2.46 of syncfusion-javascript available - shall I update?
Best regards!
Hi,
I have upgradet to the latest version (syncfusion-javascript@15.2.46) now, but it only works partially. Please see my Incident 182695 for more details, a sample project and a video recording of the problem.
Thanks!
Hi,
it should be pretty easy to get the sample project up and running, please follow these steps:
So overall it seems like the detail expansion only works, if expanded row by row in order starting from the first row...
Hi Seeni,
I still see the behaviour shown in the video, even with 15.2.46 (although you previously mentioned this should work starting from 15.2.0.40 (!)). I did the following in the sample project you received last week:
This shows the exact same behaviour - expanding the first item works, expanding any non-sequential next item (e.g. the fourth item) does not work.
Did you actually try to run my sample?
Best regards!
Hi Seeni,
thanks for the clarification. However, what was quite disappointing, is that you recommended twice upgrading your software will fix the problem - so this wrong information wasted quite some time on my end.
It is as it is - so I will wait for the update.
Best regards!
@Component({
selector: 'grid2',
template: `<ej-grid [dataSource]='data'>
</ej-grid>`,
styles: [`:host ::ng-deep .e-grid .e-rowcell {
color: red
}`]
}) |