This is a migrated thread and some comments may be shown as answers.

Iterate through all items on all pages

7 Answers 752 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kris
Top achievements
Rank 1
Kris asked on 05 Apr 2010, 08:35 PM
I am doing a custom export to excel where I load the grid, say 10 items on the first page, 3 pages long. The user then filters the grid using the built in filter column headers. That limits the grid to 14 items in 2 pages. The user clicks my export button where the following gets executed:


        /// <summary> 
        /// Exports data in grid to excel 
        /// </summary> 
        public void Export() 
        { 
            //rgdProjectWorksheets.ExportSettings.ExportOnlyData = true; 
            //rgdProjectWorksheets.ExportSettings.IgnorePaging = true; 
            //rgdProjectWorksheets.MasterTableView.ExportToExcel(); 
 
            PWDetailAccess pwa = new PWDetailAccess(); 
            DataTable dt = pwa.GetFlatExportData(Convert.ToInt32(Session[ApplicationConstants.SessionVariables.OrganizationID].ToString())); 
 
            List<int> idlist = GetVisibleIDList(); 
 
            HttpContext context = HttpContext.Current; 
            context.Response.Clear(); 
            foreach (DataColumn column in dt.Columns) 
            { 
                context.Response.Write(column.ColumnName + ","); 
            } 
            context.Response.Write(Environment.NewLine); 
            foreach (DataRow row in dt.Rows) 
            { 
                if (!idlist.Contains(Convert.ToInt32(row[PWDetailsSchema.ID].ToString()))) 
                    continue
                for (int i = 0; i < dt.Columns.Count; i++) 
                { 
                    context.Response.Write(row[i].ToString().Replace(","string.Empty) + ","); 
                } 
                context.Response.Write(Environment.NewLine); 
            } 
 
            context.Response.ContentType = "text/csv"
            context.Response.AppendHeader("Content-Disposition""attachment; filename=SA_FlatExport.csv"); 
            context.Response.End(); 
        } 
 
        private List<int> GetVisibleIDList() 
        { 
            List<int> idlist = new List<int>(); 
            for (int i = 0; i < rgdProjectWorksheets.MasterTableView.Items.Count; i++) 
            { 
                if (rgdProjectWorksheets.Items[i].Visible == true
                    idlist.Add(Convert.ToInt32(rgdProjectWorksheets.Items[i][PWDetailsSchema.ID].Text)); 
            } 
            return idlist; 
        } 

I compare my full custom datatable with the items in the grid to decide which items in my datatable I will include in the export. This works great on a grid with no paging. The problem arises when I have more than one page. It appears that the count in
rgdProjectWorksheets.MasterTableView.Items only holds the items on the current page. How do I iterate through all the items in all pages?


I've tried running the GetVisibleIDList method in the PreRender event (as this post suggests), but that does not seem to be working.
Any help would be much appreciated.
Thanks
Kris

7 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Apr 2010, 06:43 AM
Hello Kris,

As you have observed correctly, RadGrid keeps only the current page of data when paging is enabled. It never requests or processes any other data than the current page. You have access to whatever data RadGrid is bound only. This is why, with paging, you cannot get data in other pages.

If you need to bind RadGrid to all the data in all pages, you need to disable paging (set AllowPaging="false"), Rebind, and then iterate over your items. Still, if you have access to the data, iterating over all your data items yourself may be quicker than disabling paging, binding the grid and then re-enabling paging and rebinding.

Best wishes,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kris
Top achievements
Rank 1
answered on 09 Apr 2010, 11:23 PM
Ok, thanks for the reply. It would be nice if it cached all the records somewhere to prevent the re-binding of the grid, but this will do for now.

One note though, when re-binding, you need to rebind the MasterTableView, not the grid object itself.

For example, this doesn't work
 
            rgdProjectWorksheets.AllowPaging = false
            rgdProjectWorksheets.Rebind(); 

but this does
 
            rgdProjectWorksheets.MasterTableView.AllowPaging = false
            rgdProjectWorksheets.MasterTableView.Rebind(); 


0
Veli
Telerik team
answered on 12 Apr 2010, 01:54 PM
Hello Kris,

RadGrid does not cache any data it is bound two. There are many reasons for this, 2 of the most important being:

1. Where to cache? Caching in the ViewState is a performance nightmare. Caching in Session can be problemmatic for many users and large data sets.

2. How to provide concurrency? What happens when a piece of data is updated outside of the grid, but the grid keeps rebinding to stale data from the cache?

Still, if you believe caching data suits your needs, it can be implemented relatively easily by the developer, so I believe this is more or less out of scope for RadGrid.

As for setting AllowPaging from RadGrid's object, I do not seem to observe any differences. Both approaches seem to work OK. Attaching sample page used for testing.

Sincerely yours,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Chanan Zass
Top achievements
Rank 1
answered on 22 Jun 2014, 03:24 PM

Dim pageCount As Integer = RadGrid1.MasterTableView.PageCount
        Dim i As Integer = 0
        While i < pageCount
            RadGrid1.CurrentPageIndex = i
            RadGrid1.Rebind()
 
            For Each r As GridDataItem In RadGrid1.MasterTableView.Items
                  ' do something
            Next
            i += 1
        End While
0
Justin
Top achievements
Rank 1
answered on 29 Jul 2014, 11:48 AM
Thank you so much Kris for your post.  I was binding to the radgrid, not the mastertable.  Your post finally got me over the hump I've been stuck on since yesterday afternoon.
0
w
Top achievements
Rank 1
answered on 13 Dec 2014, 07:39 PM
May I check with you, the latest RadGrid Q3 2014 version still not cache all the data (ignore paging) at client side?
0
Konstantin Dikov
Telerik team
answered on 17 Dec 2014, 09:43 AM
Hello,

For the same reasons that were pointed out in the previous posts in this thread, RadGrid does not have server-side caching.

Nevertheless, if you are using client-side binding, you can take advantage of the client-side caching functionality, by setting the ClientSettings.DataBinding.EnableCaching property to true. You can find additional information on this matter in the following help article, section Client-Side Caching:

Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Kris
Top achievements
Rank 1
Answers by
Veli
Telerik team
Kris
Top achievements
Rank 1
Chanan Zass
Top achievements
Rank 1
Justin
Top achievements
Rank 1
w
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or