Xuất excel cho phép xuất dữ liệu Lưới sang tài liệu Excel. Bạn cần sử dụng phương pháp để xuất. Để bật tính năng xuất Excel trong lưới, hãy đặt giá trị là true
Để sử dụng tính năng xuất excel, bạn cần đưa mô-đun
EJ2 Grid
Loading....
1 vào lưới________một_______
EJ2 Grid
Loading....
Hiển thị spinner trong khi xuất
Bạn có thể hiển thị/ẩn thành phần spinner trong khi xuất lưới bằng các phương pháp
EJ2 Grid
Loading....
2/
EJ2 Grid
Loading....
3. Bạn có thể sử dụng sự kiện
EJ2 Grid
Loading....
4 để hiển thị công cụ quay vòng trước khi xuất và ẩn một công cụ quay trong sự kiện
EJ2 Grid
Loading....
5 hoặc
EJ2 Grid
Loading....
6 sau khi xuấtTrong sự kiện
EJ2 Grid
Loading....
4, dựa trên tham số
EJ2 Grid
Loading....
8 là
EJ2 Grid
Loading....
9 hoặc import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
grid.showSpinner[];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
grid.showSpinner[];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.hideSpinner[];
}
grid.excelExportComplete = [] => {
grid.hideSpinner[];
}
0, chúng ta có thể gọi phương thức
EJ2 Grid
Loading....
2 từ grid instanceTrong sự kiện
EJ2 Grid
Loading....
5 hoặc
EJ2 Grid
Loading....
6, chúng ta có thể gọi phương thức
EJ2 Grid
Loading....
3Trong bản demo bên dưới, chúng tôi đã kết xuất thành phần spinner mặc định khi xuất lưới
________mười một_______
EJ2 Grid
Loading....
Nguồn dữ liệu tùy chỉnh
Xuất excel cung cấp tùy chọn để xác định nguồn dữ liệu động trước khi xuất. Để xuất dữ liệu động, hãy xác định
import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
grid.showSpinner[];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
grid.showSpinner[];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.hideSpinner[];
}
grid.excelExportComplete = [] => {
grid.hideSpinner[];
}
5 trong import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
grid.showSpinner[];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
grid.showSpinner[];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.hideSpinner[];
}
grid.excelExportComplete = [] => {
grid.hideSpinner[];
}
6________hai mươi_______
EJ2 Grid
Loading....
Truyền tham số bổ sung cho máy chủ khi xuất
Bạn có thể truyền tham số bổ sung trong thuộc tính
import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
grid.showSpinner[];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
grid.showSpinner[];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.hideSpinner[];
}
grid.excelExportComplete = [] => {
grid.hideSpinner[];
}
7 bằng cách gọi phương thức import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
grid.showSpinner[];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
grid.showSpinner[];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.hideSpinner[];
}
grid.excelExportComplete = [] => {
grid.hideSpinner[];
}
8. Trong sự kiện
EJ2 Grid
Loading....
4, bạn có thể định nghĩa tham số là cặp khóa và giá trị để nó nhận ở phía máy chủ khi xuấtTrong ví dụ dưới đây, chúng tôi đã chuyển
EJ2 Grid
Loading....
0 thành
EJ2 Grid
Loading....
1 bằng cách sử dụng phương thức import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
grid.showSpinner[];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
grid.showSpinner[];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.hideSpinner[];
}
grid.excelExportComplete = [] => {
grid.hideSpinner[];
}
8import { Grid, Page, Toolbar, PdfExport, ExcelExport } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
import { Query } from '@syncfusion/ej2-data';
Grid.Inject[Page, Toolbar, PdfExport, ExcelExport];
let queryClone: Object;
let grid: Grid = new Grid[{
dataSource: data,
allowPaging: true,
allowPdfExport: true,
allowExcelExport: true,
toolbar: ['PdfExport', 'ExcelExport'],
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', visible: false },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
{ field: 'ShipCity', headerText: 'ShipCity', textAlign: 'Right', width: 140 }
],
height: 230
}];
grid.appendTo['#Grid'];
grid.toolbarClick = [args: Object] => {
if [args['item'].id === 'Grid_pdfexport'] {
queryClone = grid.query;
grid.query = new Query[].addParams["recordcount", "12"];
grid.pdfExport[];
}
if [args['item'].id === 'Grid_excelexport'] {
queryClone = grid.query;
grid.query = new Query[].addParams["recordcount", "12"];
grid.excelExport[];
}
}
grid.pdfExportComplete = [] => {
grid.query = queryClone;
}
grid.excelExportComplete = [] => {
grid.query = queryClone;
}
EJ2 Grid
Loading....
Bạn có thể chuyển các bản ghi đã chọn đến máy chủ với sự trợ giúp của yêu cầu ajax. Trong sự kiện
EJ2 Grid
Loading....
4, bạn có thể lấy các bản ghi đã chọn bằng phương thức và chuyển các bản ghi đã chọn tới máy chủ bằng thuộc tính dữ liệu của ajaximport { Grid, Page,Toolbar } from '@syncfusion/ej2-grids';
import { Ajax } from '@syncfusion/ej2-base';
Grid.Inject[Page,Toolbar];
let grid: Grid = new Grid[{
dataSource: data,
allowSelection: true,
toolbar: ['Selected'],
columns: [
{ type: 'checkbox', width: 50, },
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120},
{ field: 'CustomerID', width: 140, headerText: 'CustomerID'},
{ field: 'ShipCity', headerText: 'Ship Country', width: 140 }
],
toolbarClick: function [args] {
if [args.item.text === 'Selected'] {
var selectedRecord = this.getSelectedRecords[];
var ajax = new Ajax[{
url: "/Home/SelectRecord",
type: "POST",
contentType: "application/json",
data: JSON.stringify[selectedRecord],
successHandler: function [response] {
console.log[JSON.parse[response]];
},
failure: function [response] {
alert[response];
}
}];
ajax.send[];
}
},
}];
grid.appendTo['#Grid'];
Chi tiết bản ghi đã chọn được liên kết với tham số
EJ2 Grid
Loading....
5. Vui lòng tham khảo ảnh chụp màn hình sau