1. Get the data from the foreground DataGrid in the first step
var rows = $ (' #tb). DataGrid ("GetRows");
if (Rows.length = = 0) {
$ ("#ShowMsg"). HTML ("No data available for export!");
Return
}
var columns = new Array ();
var fields = $ (' #tb). DataGrid (' Getcolumnfields ');
for (var i = 0; i < fields.length; i++) {
var opts = $ (' #tb). DataGrid (' Getcolumnoption ', fields[i]);
var column = new Object ();
Column.field = Opts.field;
Column.title = Opts.title;
Columns.push (column);
}
var excelworksheet = new Object ();
Excelworksheet.rows = rows;
excelworksheet.columns = columns;
Excelworksheet.sheetname = "name";
2. Publish the POST request to the background
$.post ("Xxxx.aspx", {isaction: ' Method ', Acttype: ' Exportxls ',
ExcelWorkSheet:JSON.stringify (excelworksheet)//Convert data to JSON string
},
function (data) {
After successful operation
}
);
3. After converting the JSON string into a DataTable in the background, write to the Excel template;
Import Datagird data from jquery Easyui into Excel