This example demonstrates how to use different grid settings to display the grid in the view and to export its data.
The main idea of this approach is to pass a parameter to the method that creates GridViewSettings to indicate if the settings are created to display the grid or export data.
Display Grid
@Html.DevExpress().GridView(HomeController.ExportHelper.GetGridViewSettings(false)).Bind(Model).GetHtml()
Export Data
public ActionResult Export() {
var model = Product.GetProducts();
return GridViewExtension.ExportToPdf(ExportHelper.GetGridViewSettings(true), model);
}
In this example, the Columns collection contains a different set of columns based on the isExport
parameter value.
public static class ExportHelper {
static public GridViewSettings GetGridViewSettings(bool isExport) {
GridViewSettings settings = new GridViewSettings();
// ...
if (isExport) {
//Columns only to export
settings.Columns.Add("UnitsInStock");
settings.Columns.Add("UnitsOnOrder");
} else {
//Columns only to display on the web page
settings.Columns.Add("UnitPrice");
}
return settings;
}
}
(you will be redirected to DevExpress.com to submit your response)