Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
How to export the current displayed igGrid data (i.g. after sorting or filtering) to Excel?
posted

Hi,

I've found there are some posts or blogs about export igGrid data to Excel, but as you know, the displayed grid row or thier order will be updated when using filter, sort or others, my question is how to export the current displayed igGrid data (i.g. after sorting or filtering) to Excel not just whole data source like above posts or blogs shown?

my version is  2012.1 MVC3

BTW, on my current idea, I want to get the querystring of filtering or sorting info like loading grid data and send them back to controller, and then use GridDataSourceActionAttribute.InferFeatures(...) to parse them, I found there is method "_encodeUrl()" in infragistics.datasource.js, but unfortunately its a private method...

 

  • 23953
    Suggested Answer
    Offline posted

    Hi,

    Sorry for the delay.

    I have tree suggestions which you can try:

    Suggestion 1:

    You can extract the current state of sorting and filtering from the data source like this:
    $("#grid1").data("igGrid").dataSource.settings.sorting.expressions
    $("#grid1").data("igGrid").dataSource.settings.filtering.expressions
    Then you can construct query string and invoke your own method which will:
    1.Extract data from the database
    2.Export it to excel
    3.Return the generated file

    However this method has an obvious drawback - it's not guaranteed that the data which GridDataSourceActionAttribute returns to the grid will be equal to data which your method generates, so the exported data in the excel can be different from that displayed in the grid.

    Suggestion 2:

    You can get the current displayed data on the client like this:
    $("#grid1").data("igGrid").dataSource.dataView();
    Then you can serialize it in a hidden TEXTAREA or something and post it to the server. MVC Model binding will try to deserialize it as IEnumerable<YourModelObjec> and then you can export it to excel without querying the database.

    Suggestion 3:

    On the server your excel export method can call the method which returns data to the grid(the method with GridDataSourceActionAttribute attribute). Then examine the ViewResult.Model. I guess there will be the resulting data.

    In order to construct the correct query string on the client you can use the approach from Suggestion 1 or you can call the private _encodeUrl() like this:
    $("#grid1").data("igGrid").dataSource._encodeUrl()

     

    Best regards,
    Martin Pavlov
    Infragistics, Inc.