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.

Add additional column on export only

Thread ID:

Created:

Updated:

Platform:

Replies:

130722 May 29,2017 05:38 AM May 31,2017 12:09 AM ASP.NET MVC 3
loading
Tags: Grid
Frankie Moran
Asked On May 29, 2017 05:38 AM

Hi there, 

Looking for a bit of help when exporting an additional column. 

I have a grid which has a number of columns and I want to export the grid as it is but also add an additional column on the end which will show the last comment against each row. Currently, when it exports I am retrieving the datasource again and have the code sitting there to pull back the last comment for each row, however, it doesn't show on the exported file. It only exports the columns which were on the original grid and doesn't take into account the new datasource data. 

Is there anyway of rendering this additional column without having to show it on the grid? 

Cheers,
Frankie

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On May 30, 2017 07:17 AM

Hi Frankie,  
 
Thanks for contacting Syncfusion Support.  
 
We have Assigned the Columns to the Grid using ViewBag after collecting required columns from the initial load of the page. Required columns were added to the Grid model before exporting them. Refer to the following code example.  
 
@{Html.EJ().Grid<object>("Grid") 
         .Datasource((IEnumerable<object>)ViewBag.data) 
        .AllowPaging() 
        .ToolbarSettings(toolbar => 
        { 
            toolbar.ShowToolbar() 
                .ToolbarItems(items => 
                { 
                    items.AddTool(ToolBarItems.ExcelExport); 
                    items.AddTool(ToolBarItems.PdfExport); 
                    items.AddTool(ToolBarItems.WordExport); 
                }); 
        }) 
        //Collect the ViewBag columns and assign them to the Grid Columns 
        .Columns(ViewBag.columns) 
        .Render(); 
} 
 
    public class HomeController : Controller 
    { 
        public static List<Orders> order = new List<Orders>(); 
        public static List<Column> cols = new List<Column>(); 
        public ActionResult Index() 
        { 
               . . . 
                     . . . 
            /* Add Grid Columns 
             * intial Load of the Page 
             * Save it in Global and static Variable 
             * Assign them to ViewBag 
             */ 
            cols.Add(new Column() { Field = "OrderID", HeaderText = "Order ID" }); 
            cols.Add(new Column() { Field = "CustomerID", HeaderText = "Order ID" }); 
            cols.Add(new Column() { Field = "EmployeeID", HeaderText = "Order ID" }); 
            cols.Add(new Column() { Field = "Freight", HeaderText = "Order ID" }); 
            ViewBag.columns = cols; 
 
            return View(); 
        } 
        public void addColumns(GridProperties gridObj){ 
            if (cols.Count == gridObj.Columns.Count) 
                cols.Add(new Column() { Field = "ShipCity", HeaderText = "Ship City" }); 
            gridObj.Columns = cols; 
        } 
        public void ExportToExcel(string GridModel) 
        { 
 
            ExcelExport exp = new ExcelExport(); 
            var DataSource = order; 
            GridProperties obj = ConvertGridObject(GridModel); 
            //Push the additional columns before exporting the Grid. 
            addColumns(obj); 
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
           . .  
               . . 
    } 
 
 
Regards,  
Seeni Sakthi Kumar S. 


Frankie Moran
Replied On May 30, 2017 10:58 AM

Managed to get round the issue with your help! 

Thanks! 


Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On May 31, 2017 12:09 AM

Hi Frankie,  
 
Thanks for the update. We are happy to hear that your requirement has been achieved and you are good to go. Please get back to us, if you require further assistance on this.  
 
Regards,  
Seeni Sakthi Kumar 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.

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.

;