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. Image for the cookie policy date

Add additional column on export only

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

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team May 30, 2017 11:17 AM UTC

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. 



FM Frankie Moran May 30, 2017 02:58 PM UTC

Managed to get round the issue with your help! 

Thanks! 



SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team May 31, 2017 04:09 AM UTC

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. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon