)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export client-side data in TreeGrid

Platform: ASP.NET MVC |
Control: TreeGrid |
Published Date: April 5, 2018 |
Last Revised Date: May 29, 2019

In TreeGrid, it is possible to export the client-side data. This can be achieved by convert the TreeGrid data source to JSON string and send it as new property to the TreeGrid model before calling the export method.

CSHTML

<script>
function exportPDF() {
var treeObj = $("#TreeGridContainer").ejTreeGrid("instance");
treeObj.model["exportData"] = JSON.stringify(treeObj.dataSource());
treeObj.exportGrid = treeObj["export"];
treeObj.exportGrid("Treegrid/ExportToPdf", "", false);
}
function exportExcel() {
var treeObj = $("#TreeGridContainer").ejTreeGrid("instance");
treeObj.model["exportData"] = JSON.stringify(treeObj.dataSource());
treeObj.exportGrid = treeObj["export"];
treeObj.exportGrid("Treegrid/ExportToExcel", "", false);
}
</script>

 

C#

public void ExportToPdf(string TreeGridModel)
{
PdfExport exp = new PdfExport();
TreeGridProperties obj = ConvertTreeGridObject(TreeGridModel);
exp.Export(obj, exportData, new TreeGridExportSettings() { Theme = ExportTheme.FlatSaffron }, "Export");
}
public void ExportToExcel(string TreeGridModel)
{
ExcelExport exp = new ExcelExport();
TreeGridProperties obj = ConvertTreeGridObject(TreeGridModel);
exp.Export(obj, exportData, "Export.xlsx", ExcelVersion.Excel2010, new TreeGridExportSettings() { Theme = ExportTheme.FlatSaffron });
}
private TreeGridProperties ConvertTreeGridObject(string gridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
TreeGridProperties gridProp = new TreeGridProperties();
foreach (KeyValuePair<string, object> ds in div)
{
var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (ds.Key == "exportData")
{
string str = Convert.ToString(ds.Value);
exportData = JsonConvert.DeserializeObject<IEnumerable<BusinessObject>>(str);
continue;
}
if (property != null)
{
Type type = property.PropertyType;
string serialize = serializer.Serialize(ds.Value);
object value = serializer.Deserialize(serialize, type);
property.SetValue(gridProp, value, null);
}
}
return gridProp;
}

A sample to export TreeGrid with client-side data is available here

 

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon