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

Export only filtered data in grid

Thread ID:

Created:

Updated:

Platform:

Replies:

126275 Oct 5,2016 09:57 AM UTC Oct 12,2016 01:36 PM UTC JavaScript 4
loading
Tags: ejGrid
Dina Abdelbary
Asked On October 5, 2016 09:57 AM UTC

I have a grid, and i make some filters on it, and i wanna export only the filtered data (grid datasource), and not access the server to get the data again.
i use this js to get the datasource property with gridmodel data, and not to exclude it:
function databound() {
var grid = $('#Grid').ejGrid('instance');
grid.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1);
}
databound();

i write this function after initializing the grid:
$(function () {
$("#Grid")
.ejGrid({....

but an error appears saying "Uncaught ejGrid: methods/properties can be accessed only after plugin creation
Error: ejGrid: methods/properties can be accessed only after plugin creation
at t.throwError (http://localhost:7483/Scripts/ej/ej.web.all.min.js:10:26512)
at x.n.fn.(anonymous function) [as ejGrid] (http://localhost:7483/Scripts/ej/ej.web.all.min.js:10:20725)
at databound (http://localhost:7483/RepControlsDemo.html:711:31)
at http://localhost:7483/RepControlsDemo.html:718:5"

i don't know the solution, and i wanna solve it ASAP
Thanks

Mohammed Farook J [Syncfusion]
Replied On October 6, 2016 11:48 AM UTC

Hi Dina, 

Thanks for contacting Syncfusion Supports. 

We have validated your provided code, you have do you applied custom filter in before data binding in Grid. please use the “load”  event  of Grid For push the property in ignoreonExport. 

Please find the code example. 




       $("#Grid").ejGrid({ 
 
            load: function (args) { 
                this.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1); 
            } 
        }) 




Using “this” key word in inside Grid event.  This  is return Grid instance. No need to create instance in inside the Grid events. 

Regards, 
J.Mohammed Farook 


Dina Abdelbary
Replied On October 11, 2016 09:14 AM UTC


i ve put the load event u sent at the definition of the grid, 

" $(function () {
        $("#Grid")
            .ejGrid({
                load: function (args) {
                    this.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1);
                },
                dataSource: data,
                allowPaging: true,
                allowSorting: true,"...."

but there is an error

"Uncaught ReferenceError: grid is not defined", so what is the "grid" variable?


Dina Abdelbary
Replied On October 11, 2016 09:23 AM UTC


i ve put the load event u sent at the definition of the grid, 

" $(function () {
        $("#Grid")
            .ejGrid({
                load: function (args) {
                    this.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1);
                },
                dataSource: data,
                allowPaging: true,
                allowSorting: true,"...."

but there is an error

"Uncaught ReferenceError: grid is not defined", so what is the "grid" variable?


Karthick Kuppusamy [Syncfusion]
Replied On October 12, 2016 01:36 PM UTC

Hi Dina, 

We suspect that you have passed the grid model dataSource to server side upon exporting. In such case, we need to handle the dataSource at server side. Please refer to the below code example.  
 
 
$("#Grid").ejGrid({ 
                // the datasource "window.gridData" is referred from jsondata.min.js 
                dataSource:window.gridData, 
                allowPaging: true, 
                allowFiltering:true, 
                dataBound:databound, 
                toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.ExcelExport] }, 
                columns: [ 
                     .  
                     . 
                           ] 
            }); 
 
        }); 
 
 
   function databound(args){ 
        var grid = $('#Grid').ejGrid('instance'); 
        grid.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1); 
    } 
 
 
Server Code. 
 
 
public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            
            GridProperties obj = ConvertGridObject(GridModel); 
            exp.Export(obj, (IEnumerable)(obj.DataSource), "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");  
        } 
        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 == "dataSource") 
                { 
                    string serialize = serializer.Serialize(ds.Value); 
                    gridProp.DataSource = serializer.Deserialize<List<OrdersView>>(serialize);//here we need to deserialize the gridDatasource 
                } 
                else 
                { 
                    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; 
        } 
     
 
 
For your convenience we have created sample to splice the grid dataSource property on ‘ignoreOnExport’ method then handle the grid model dataSource in server side. http://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionMvcApplication82-1516137963-1329944920.zip. 


Please refer the following UG link for more information. 

Please let us know if you have any concern. 

Regards, 
K.Karthick. 


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

;