Hi,
I want to add the Grid Component to a Angular 11 project. I tried something really simple:
html:
TS:
But then I get the following error:
error TS2564: Property 'grid' has no initializer and is not definitely assigned in the constructor.
So my first question is how to initialize the grid component in the constructor?
Then I what I actually want to achieve is to dynamically load an Excel file in to the grid with the catch that the file can be one of five different templates, so the columns will vary depending on each template. So I was thinking on reading the Excel file and removing and adding the columns programmatically but I'm open to any suggestions.
columns: [
{ 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 }
]
|
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right'></e-column>
<e-column field='CustomerName' headerText='Customer Name' width='150'></e-column>
<e-column field='OrderDate' headerText='Order Date' width='130' format="yMd" textAlign='Right'></e-column>
<e-column field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right'></e-column>
<e-column field='ShippedDate' headerText='Shipped Date' width='130' format="yMd" textAlign='Right'></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width='150'></e-column>
</e-columns>
|
Hi, I want to achieve the same thing as well. I am using Angular and I want to
Hi Ronald Koh,
Upon reviewing your query, we noticed that you need to programmatically render the Syncfusion Grid within Angular. We have developed a basic sample based on your specifications, which involves creating a Grid, assigning the necessary data source, and programmatically exporting it to an Excel document. For more detailed information, please consult the provided sample, code snippet, and documentation link.
App.component.ts
<ejs-grid #grid id='Grid' [columns]='columns' [toolbar]='toolbarOptions' [allowExcelExport]='true' (toolbarClick)='toolbarClick($event)'> </ejs-grid>
export class AppComponent implements OnInit {
@ViewChild('grid') public grid!: GridComponent;
public data: Object[] = [ { OrderID: 10248, CustomerID: 'VINET', Freight: 32.38, ShipCountry: 'Germany' }, { OrderID: 10249, CustomerID: 'TOMSP', Freight: 11.61, ShipCountry: 'France' } ];
public columns: ColumnModel[] = [ { field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right' }, { field: 'CustomerID', headerText: 'Customer Name', width: 150 }, { field: 'Freight', headerText: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }, { field: 'ShipCountry', headerText: 'Ship Country', width: 130 } ];
public toolbarOptions?: ToolbarItems[];
ngOnInit() { this.toolbarOptions = ['ExcelExport']; }
ngAfterViewInit() { this.grid.dataSource = this.data; }
toolbarClick(args: ClickEventArgs): void { if (args.item.id === `${this.grid.element.id}_excelexport`) { // Grid component id + _ + toolbar item name this.grid.excelExport(); } }
}
|
Sample: https://stackblitz.com/edit/github-dp76ix-iciuag?file=src%2Fapp.component.ts,src%2Fdatasource.ts
Documentation Link: Excel-exporting
If you need any further assistance or have additional questions, please feel free to let us know.
Regards
Aishwarya R