This is a migrated thread and some comments may be shown as answers.
Problem while exporting with filter, paging options
4 Answers 63 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aayushi
Top achievements
Rank 1
Aayushi asked on 06 Sep 2010, 08:34 AM
Hello,

   I have found the code to take the export to csv at one of your web documents. Below is the link :
           http://demos.telerik.com/aspnet-mvc/grid/customcommand.

 I have implement same thing in my code to take export, and it is working,
  But when I use  filter the grid with option like column name "Name" , then in grid the resultant view show the filtered data, but when I export them , it still expoting the previous view data which are before filltering:

Here is the code in my exporttocsv() action method:
 
public ActionResult exporttocsv(int page, string orderBy, string filter)
        {
             IEnumerable details = getList().AsQueryable().ToGridModel(page, 20, orderBy, string.Empty, filter).Data;

       // remaining code is same as given on your link onlu column name are changes)

}

After filtring  when exporttocsv() is called by clickng on "ExportToCsv" button. In that method parameter all the all  page, string orderBy, string filter are 1,~,~ respectively. As on view we are passing thats . See below

<%= Html.Telerik().Grid(Model)
       
.Name("Grid")
       
.ToolBar(commands => commands
           
.Custom()
               
.HtmlAttributes(new { id = "export" })
               
.Text("Export to CSV")
               
.Action("ExportCsv", "Grid", new { page = 1, orderBy = "~", filter =
                   
"~" }))
 
%>.


So how can I pass at runtime the filter argument, page, order by, so it will export the filtered data.


Thanks
Aayushi Soni

4 Answers, 1 is accepted

Sort by
0
lydia
Top achievements
Rank 1
answered on 06 Sep 2010, 09:56 AM
hi,
i have the same problem when i tried export grid to excel
but when i run the demo code provided in the forums it work but in my application the problem percisst
what have you do to solve this problem i tried but i don't found any things
thanks
0
Aayushi
Top achievements
Rank 1
answered on 06 Sep 2010, 10:21 AM
Hi,

 I have found the solution, we can get the filtered name, page size  using Request.QueryString[] like in export  method:

 IEnumerable details = getList().AsQueryable().ToGridModel(page, 20, orderBy, string.Empty, Request.QueryString["Grid-filter"]).Data;
similarly you can get other things from url.
0
lydia
Top achievements
Rank 1
answered on 15 Sep 2010, 02:46 PM
hi
i tried this but doesn't work ,i don't understund why
cun you give me an example
thanks
0
lydia
Top achievements
Rank 1
answered on 15 Sep 2010, 03:07 PM
this is my code the only différence consist in the routes object (i add "id" )
<%=Html.Telerik().Grid(Model)
         .Name("Grid")
          
          
 
               .Columns(columns =>
             {
                 columns.Bound(o => o.CodeRubrique).Width(50).Title("Code");
                 columns.Bound(o => o.LibelleRubrique).Width(200).Title("LibellĂ©");
                 columns.Bound(o => o.MontantRub).Width(100);
                 columns.Bound(o => o.ElmntSta).Width(60);
                 columns.Bound(o => o.Nature).Width(40);
             }
                )
                .Pageable(page => page.PageSize(25)).Filterable()              
                 .ClientEvents(events => events.OnDataBound("OnDataBound"))
           
     
               
      %>
  <%= Html.ActionLink("Export to Excel", "Export", new { page = 1, orderBy = "~", filter = "~"},id=ViewData["id"], new { id = "exportLink" }) %>
and i Personalize the Action export to Excel have four arguments on entree
Tags
General Discussions
Asked by
Aayushi
Top achievements
Rank 1
Answers by
lydia
Top achievements
Rank 1
Aayushi
Top achievements
Rank 1
Share this question
or