Ignore send the datasource to server of a Dropdownedit type column when exporting

I try to export my Grid at the moment of doing so it sends all the datasource of my DropDownType columns.

Tag Helper
<e-column field="PositionId"
                      header-text="Puesto"
                      header-text-align="TextAlign.Center"
                      type="string"
                      edit-type="DropdownEdit"
                      datasource="Model.Positions"
                      foreign-key-field="Id"
                      foreign-key-value="Name"
                      width="250"
                      drop-down-edit-options="@(new Syncfusion.JavaScript.Models.DropDownListProperties(){
                        WatermarkText = "Seleccione un puesto",
                        EnableFilterSearch = true, FilterType = SearchFilterType.Contains })" />

Code 
public async Task<IActionResult> ToExcelEmployees(string GridModel)
        {
            ExcelExport exp = new ExcelExport();

            await GetEmployees();
            await GetCostCentres();
            await GetLocations();
            await GetPositions();

            GridProperties gridProp = ConvertGridObject(GridModel);
            GridExcelExport excelExp = new GridExcelExport();
            excelExp.FileName = "Empleados.xlsx"; excelExp.Excelversion = ExcelVersion.Excel2010;
            excelExp.Theme = "flat-saffron";

            gridProp.Columns[8].DataSource = CostCentres;
            gridProp.Columns[9].DataSource = Positions;
            gridProp.Columns[10].DataSource = Locations;
            gridProp.Columns[11].DataSource = Employees;

            return exp.Export(gridProp, Employees, excelExp);
        }


GridModel cotains in propertie columns the columns with de datasource, how to ignore the datasource of columns to send to server??


Greetings.


1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 16, 2018 04:40 PM UTC

Hi Alberto, 

Thanks for contacting Syncfusion Support. 

We have checked your query and we have achieved your requirement using ToolbarClick event of the Grid. In the server-end, we are setting some cookies. This has been watched by the client-end whether any cookie present. While on Exporting, the datasource become null and the null values are passed to the serverside. Once the response is released from the server-end, browser cookies were turned off and updated the datasource for the columns. 

 Refer to the code example:- 

<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="true"> 
        <ClientSideEvents ToolBarClick="toolBarClick" /> 
       <Columns> 
               .  .   . 
               <ej:Column Field="EmployeeID" HeaderText="Employee Name" EditType="DropdownEdit" ForeignKeyField="EmployeeID" 
                    ForeignKeyValue="FirstName" TextAlign="Left" Width="90" />           
            </Columns> 
            
</ej:Grid> 
 
    <script type="text/javascript"> 
        var obj = $('#<%= OrdersGrid.ClientID %>').ejGrid("instance");  
        var data = obj.model.columns[2].dataSource; 
        function toolBarClick(args) { 
            var proxy = this; 
            var data = this.model.columns[2].dataSource; 
            data = []; 
            var testVar = setInterval(ej.proxy(function () { 
                if (document.cookie.search("Export") != -1) { 
                    //delete cookie 
                    data= this.model.columns[2].dataSource; 
                    clearInterval(testVar); 
                } 
            }, this), 100); 
   } 
 
Serverside:- 
 
          protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e) 
            { 
                ExcelExport exp = new ExcelExport(); 
                //Setting the cookie 
                Response.Cookies["Export"]["isdone"] = "done"; 
                exp.Export(FlatGrid.Model, dt, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime"); 
            } 


Refer to the API Link:- 
Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 


Loader.
Up arrow icon