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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Javascript | TreeGrid | Export to Excel with dynamic columns

Thread ID:

Created:

Updated:

Platform:

Replies:

123872 Apr 28,2016 08:44 AM UTC May 5,2016 11:52 AM UTC ASP.NET MVC 3
loading
Tags: TreeGrid
Martin R
Asked On April 28, 2016 08:44 AM UTC

Hello, 

I want to ask if is somehow possible to export treeGrid with dynamic columns. 

My following code throws an null poiner exception in exp.Export call:

Setup in JS:
---------------
                actionComplete: function (args) {
                    args.model.filteredRecords = TreeGridJs.DataSource;
                }
                treegridObj.export("api/ExportGridAsExcel");

Handle in C#:
---------------
    [RoutePrefix("api/ExportGridAsExcel")]
    public class ExportController : ApiController
    {
        //Excel Export Method.
        [HttpPost]
        [Route("")]
        public void ExcelExport()
        {
            string gridModel = HttpContext.Current.Request.Params["TreeGridModel"];
            GridProperties gridProperty = ConvertGridObject(gridModel);
            ExcelExport exp = new ExcelExport();

            exp.Export(gridProperty, (IEnumerable)gridProperty.DataSource, "Export.xlsx", ExcelVersion.Excel2010); //Here the System.NullReferenceException occurs, reffered in https://www.syncfusion.com/kb/3018/Null-Exception-while-exporting

        }

        //Grid Model conversion Method.
        private GridProperties ConvertGridObject(string gridProperty)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
            GridProperties gridProp = new GridProperties();

            foreach (KeyValuePair<string, object> ds in div)
            {
                if (ds.Key == "filteredRecords")
                {
                    string serialize = serializer.Serialize(ds.Value);
                    dynamic dynamicDataSource = new List<dynamic>();
                    var dataSource = serializer.Deserialize<IEnumerable<Dictionary<string, object>>>(serialize);
                    foreach (var dictionary in dataSource)
                    {
                        dynamic rowObject = new ExpandoObject();
                        foreach (var keyValuePair in dictionary)
                        {
                            ((IDictionary<String, Object>)rowObject).Add(keyValuePair.Key, keyValuePair.Value);
                        }
                        dynamicDataSource.Add((dynamic)rowObject);
                    }
                    gridProp.DataSource = dynamicDataSource;
                    continue;
                }
                var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
                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;
        }
    }


Mahalakshmi Karthikeyan [Syncfusion]
Replied On April 29, 2016 10:15 AM UTC

Hi Martin, 
Thanks for contacting Syncfusion support. 
At present there is no Excel Export support in TreeGrid control. But it is possible to export the Grid control to Excel. Can please provide us more information on your requirement? Do you want export support for TreeGrid control or Grid Control. Since you have using TreeGrid control in view page and processing the GridProperties in the Code behind. 
Regards, 
Mahalakshmi K. 


Martin R
Replied On May 4, 2016 11:24 AM UTC

Hello Mahalakshmi K.,

we need support for exporting TreeGrid Control to Excel (Grid we used and we know that this functionality is here already). We also know that there is exporting to PDF for TreeGrid, but not to Excel format. I could imagine that the feature realization of the export to excel should send ajax request from client sending all information regarding the export (columns and datasource) to only pass it as parameters in WebApiController and get exported Excel.

Martin Rašovský.





Jonesherine Stephen [Syncfusion]
Replied On May 5, 2016 11:52 AM UTC

Hi Martin, 
Thanks for contacting Syncfusion support.  
At present there is no support for Excel exporting in TreeGrid control. For this we have already logged a feature request regarding this. 
This feature will be available in our upcoming Volume 2 main release which is expected to be rolled out by the end of June 2016. 
Please let us know if you require further assistance on this. 
Regards, 
Jone Sherine P S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;