The exportGrid method offers four parameters, but the only one you must provide a value for is the fileName.
If you want to customize your export more than these four parameters allow, you can use the wijmo.exporter.exportGrid method.
Provide a string value to use for the name of the exported file. By default, the file is saved to the Downloads folder with the name of the file, and the file extension comes from the type parameter.
By default, exportGrid creates an XLS file, but you can specify any of the following three Excel types or one document type.
In the interest of getting you up and running quickly, we set this parameter by default to point to the demo export service we have set up here:
http://demos.componentone.com/ASPNET/ExportService/exportapi/grid
You can install your own export service in IIS v7.0 or higher. For more information, see Export Service Setup.
This parameter only applies if you set the type parameter to pdf. See Grid PDF Exports for more information.
In this example, we create a button click function for an <input> button element that calls our grid, and exports it to an XLS file named "MyGridExport."
Script |
Copy Code |
---|---|
<script id="scriptInit" type="text/javascript"> require(["wijmo.wijgrid", "gridexport"], function () { $(document).ready(function () { $("#wijgrid").wijgrid({ cellClicked: function (e, args) { alert(args.cell.value()); }, allowSorting: true, data: [ [27, 'Canada', 'Adams, Craig', 'RW'], [43, 'Canada', 'Boucher, Philippe', 'D', 'R'], [24, 'Canada', 'Cooke, Matt', 'LW', 'L'], [87, 'Canada', 'Crosby, Sidney (C)', 'C', 'L'], [1, 'United States', 'Curry, John', 'G', 'L'], ], columns: [ {headerText: "Number"}, {headerText: "Country"}, {headerText: "Player"}, {headerText: "Position"} ] }); }); $("#exportXLS").button().click(function () { wijmo.exporter.exportGrid({ serviceUrl: "http://demos.componentone.com/ASPNET/ExportService/exportapi/grid", grid: $("#wijgrid").data("wijmo-wijgrid"), fileName: "MyGridExport" }); }); }); </script> |
Here is the example code above in action. Click the Export to Excel button to create a "MyGridExport.xls" file in your Downloads directory.