|
<ejs-grid #grid [dataSource]='data'>
<e-columns>
<e-column headerText='Employee Image' width='150' textAlign='Center'>
<ng-template #template let-data>
<div class="image">
<img src="./assets/grid/images/{{data.EmployeeID}}.png" alt="{{data.EmployeeID}}"/>
</div>
</ng-template>
</e-column>
<e-column field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right'></e-column>
<e-column field='FirstName' headerText='Name' width='120'></e-column> |
|
<div class="control-section">
<ejs-grid [dataSource]='data' [columns]="columns" height='350'>
</ejs-grid>
</div>
|
|
export class AppComponent {
public data: Object[] = [];
public columns: Object[];
ngOnInit(): void {
this.data = orderDetails;
this.columns = [
// here you can generate the fields dynamically
{ field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right' },
{ field: 'CustomerName', headerText: 'Customer Name', width: 150 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right' },
{ field: 'Freight', width: 120, format: 'C2', textAlign: 'Right' },
{ field: 'ShippedDate', headerText: 'Shipped Date', width: 140, format: 'yMd', textAlign: 'Right' },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150 }]
}
} |
|
export class BoldGridService extends UrlAdaptor {
. . .
public isInitial: boolean = true;
public processResponse(): object {
let request: any = super.processResponse.apply(this, arguments);
let result = [];
let count = 0;
let fields = [];
if (request.isSuccess === true) {
count = request.payload.totalNoOfRecords;
result = request.payload.records;
fields = request.payload.header;
if (this.isInitial) {
this.isInitial = false;
this.setColumns(request.payload.header);
this.assignClientColumns();
}
} else {
// handle error here!
}
//this.tableCommunicationService.requestComplete.next({ result: result, count: count, fields: fields });
return {
result: result,
count: count,
fields: fields,
currentColumns: fields,
keys: fields
};
//return { result: request.result, count: request.count, keys: fields };
} |
|
[bold-grid.component.ts]
export class BoldGridComponent implements OnInit {
@ViewChild("grid", { static: false }) public grid: AGridComponent;
@ViewChild("template ", { static: false }) public actionTemplate: any;
@ViewChild("checkItem")
public temp1: TemplateRef<{}>;
@ViewChild("actionItem")
public temp2: TemplateRef<{}>;
dataBound () {
(this.grid.getColumns()[9].template as any) = this.temp1;
(this.grid.getColumns()[10].template as any) = this.temp2;
} |
|
[bold-grid.component.html]
<ejs-grid #grid [rowHeight]="27" (dataBound)="dataBound($event)" (rowDrop)="rowDrop($event)" allowPaging="true" allowReordering="false"
allowResizing="true" [allowRowDragAndDrop]="boldGridService._hasOrderFlag" allowSorting="true"
allowEditing="true" (actionComplete)="actionComplete($event)" [showColumnChooser]="true"
[enableHeaderFocus]="false" (columnDataStateChange)="actionComplete($event)" [allowFiltering]="false"
[dataSource]="data" [pageSettings]="pageSettings" [filterSettings]="filterSettings" [toolbar]="toolbar"
[columns]="boldGridService.clientHeaders" [enableHover]="false" (actionFailure)="onActionFailure($event)">
</ejs-grid>
</div>
<ng-template id="actionItem" #actionItem let-actionItem>
<div style="height: 27px;">
<app-action-buttons [item]="actionItem" [entityType]="entityType" [actions]="gridActions"
(onActionClickEvent)="onActionClick($event)" [detailsMode]="false">
</app-action-buttons>
</div>
</ng-template>
<ng-template #checkItem let-checkItemy>
<div class="custom-control custom-switch mb-2">
<label>
<input [checked]="checkItem.isDisabled"
(click)="onActionClickEvent.emit({item: checkItem, action: 19});" type="checkbox"
class="custom-control-input">
<span class="custom-control-label"></span>
</label>
</div>
</ng-template> |
|
<ng-template id="actionItem" #actionItem let-actionItem>
custom template here
<!-- <div style="height: 27px;">
<app-action-buttons [item]="actionItem" [entityType]="entityType" [actions]="gridActions"
(onActionClickEvent)="onActionClick($event)" [detailsMode]="false">
</app-action-buttons>
</div> -->
</ng-template> |
Hi Ben,
Thanks for your update.
We have validated the provided sample and we could see that the columns are obtained from the first network request. After the request to the server only the columns are applied to the Grid, so the Grid is refreshed. Due to this case it is not feasible to prevent the second network request in initial rendering.
Regards,Manivel
Thank you @Pon Selva Jeganathan,
It is working now after change the code style like present in below sample.
https://stackblitz.com/edit/angular-vzkx8m-zu2f3a?file=app.component.html
Thanks for your reference.