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

Rad Grid View Custom Paging

3 Answers 583 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Moe
Top achievements
Rank 1
Moe asked on 22 Mar 2017, 02:41 PM

Hello,

We were looking to implement WinForms RadGridView in a small window application that consumes a RestAPI.

We would like to use custom paging in that case to send the page size, and possibly filters to the API. We see that we can get the page size and index yet we can't set the total count for the grid when we get a result back from the API.

In Web we can use custom paging by setting AllowCustomPaging = true and we can set the total item count which will affect the pager control showed pages by setting VirtualItemCount.

Can we do the same in WinForms GridView?

A sample would be great.

Thanks

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 23 Mar 2017, 08:27 AM
Hi Moe,

To achieve such functionality you can use RadVirtualGrid. With this control, all the data is loaded on demand and it supports paging:
I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Moe
Top achievements
Rank 1
answered on 23 Mar 2017, 12:34 PM

Hello Dimitar,

Thank you for your response,

What we are trying to achieve is that on initial load we call the Rest API for example to retrieve contacts with the following parameters:

  • Skip: 0
  • Top: 10

This will get us the first 10 records, and a variable stating that the total records in the database to 1000.

What we would like to do is, we instruct the Grid that virtually the total number of records is 1000 yet we load only 10 since the page size is 10. In that the grid will draw the number of pages based on the page size and the virtual total number of records.

Then we can catch the paging event and call the same API subsequently with different parameters reflecting the page index selected.

We are still not sure how that can be achieved using the RadVirtualGrid you pointed to since we tried it based on the documentation yet still we are not being able to make it 100% functional as intended. 

Here is a Sample Snippet of the Function handling the load of data:

private void PopulateContactsGrid(int pageIndex)
{
// Set how many records to skip based on the page size and index
    int skip = pageIndex * RadVirtualGridContacts.PageSize;

    int? totalRecords = 0;
// Call the API and get the of data based on the skip and page size
// the API will output the total records available in the database
    List<Contact> lstContacts = LoadContacts(skip, RadVirtualGridContacts.PageSize, out totalRecords);

// Setting the Row Count of the Grid based on the Total Records in the Database
    RadVirtualGridContacts.RowCount = totalRecords.Value;

// Set the Data of the Grid
    data = lstContacts;
}

private void RadVirtualGridContacts_PageChanging(object sender, VirtualGridPageChangingEventArgs e)
{
    PopulateContactsGrid(e.NewIndex);
}

private void btnGetContacts_Click(object sender, EventArgs e)
{
    PopulateContactsGrid(0);
}

I hope this clarifies the question and guide us if we are implementing it in a wrong way.

Thank you in advance,

 

0
Dimitar
Telerik team
answered on 23 Mar 2017, 02:23 PM
Hi Moe,

First, you need to set the RowCount of RadVirtualGrid. This way it will know how many rows to display, you can enable the paging as well:
radVirtualGrid1.RowCount = 1000;
radVirtualGrid1.ColumnCount = 3;
radVirtualGrid1.EnablePaging = true;
radVirtualGrid1.PageSize = 10;

After this, subscribe to the CellValueNeeded event. In the CellValueNeeded event handler, you need to pass the value for each cell depending on its index. The indexes are not dependent on the current page index. The event will be fired only for the rows in the current page. Examples for using this event are available in the following articles:
Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Moe
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Moe
Top achievements
Rank 1
Share this question
or