import { render } from "react-dom";
import "./index.css";
import * as React from "react";
import {
ColumnDirective,
ColumnsDirective,
ExcelExport,
GridComponent,
Group,
Inject,
Page,
Toolbar
} from "@syncfusion/ej2-react-grids";
import { orderDetails } from "./data";
import { SampleBase } from "./sample-base";
import { has, toString } from "lodash";
export class Exporting extends SampleBase {
constructor() {
super(...arguments);
this.toolbarOptions = [
{
text: "ExcelExport",
align: "right",
click: () => this.gridInstance.excelExport()
}
];
}
excelQueryCellInfo = args => {
if (has(args.column, "customExcelTemplate")) {
args.value = toString(args.column.customExcelTemplate(args.data));
}
};
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
dataSource={orderDetails}
ref={grid => (this.gridInstance = grid)}
toolbar={this.toolbarOptions}
allowPaging={true}
allowExcelExport={true}
excelQueryCellInfo={this.excelQueryCellInfo}
allowPdfExport={true}
load={this.load}
>
<ColumnsDirective>
<ColumnDirective
field="OrderID"
headerText="Order ID"
width="120"
textAlign="Right"
customExcelTemplate={rowData => "excel: " + rowData.OrderID}
template={rowData => (
<span style={{ color: "red" }}> Grid: {rowData.OrderID}</span>
)}
/>
<ColumnDirective
field="CustomerID"
headerText="Customer ID"
width="150"
/>
<ColumnDirective
field="OrderDate"
headerText="Order Date"
width="150"
format="yMd"
textAlign="Right"
/>
<ColumnDirective
field="Freight"
headerText="Freight"
width="120"
format="C2"
textAlign="Right"
/>
<ColumnDirective
field="ShipCountry"
headerText="Ship Country"
width="150"
/>
</ColumnsDirective>
<Inject services={[Page, Toolbar, ExcelExport, Group]} />
</GridComponent>
</div>
</div>
);
}
}
render(<Exporting />, document.getElementById("sample"));