I have an ultrawebgrid with the paging enabled in it. As the data to be displayed is around 10K rows, pagination is carried out by setting the LoadOnDemand="XML" property.
The issue I'm facing is when I navigate through the pages, I could see an AJAX call happening but the data displayed is only of the first page.
For ex: I have 10 pages of data, when i click on page '3' the grid displays the content of page '1' itself.
But if I sort or filter any column, sorting and filtering results are as expected.
.aspx:
<DisplayLayout BorderCollapseDefault="Separate" Name="SampleGrid" RowHeightDefault="20px" SelectTypeRowDefault="Single" Version="4.00" AllowColSizingDefault="Free" SelectTypeColDefault="Single" TableLayout="Fixed" AllowAddNewDefault="Yes" AllowSortingDefault="OnClient" AllowUpdateDefault="Yes" AutoGenerateColumns="False" CellClickActionDefault="Edit" ViewType="Hierarchical">.
<Pager><PagerStyle CssClass="igwgPgrBlack2k7" /></Pager>
</DisplayLayout>
.vb:
Protected Sub SampleGrid_InitializeDataSource(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs) Handles SampleGrid.InitializeDataSource
Dim dsData As System.Data.DataSet
Dim sql As String
dsData = DataManager.ExecuteDataset(ConnectionType.XXX, Data.CommandType.Text, sql) // getting dataset
'Me.SampleGrid.DisplayLayout.Pager.PageCount = Math.Ceiling(dsData.Tables(0).Rows.Count/Me.SampleGrid.DisplayLayout.Pager.PageSize) //on first load, i'm getting the PageSize as 8 whereas it has to be 50 rows, I tried setting the page size in 'InitializeLayout' but 'InitializeDataSource' event is called first. So where do i set the grid's PageSize.
SampleGrid.DataSource = dsData
End Sub
Protected Sub SampleGrid_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles SampleGrid.InitializeLayout
Dim htmlString As New StringBuilder
SampleGrid.Browser = BrowserLevel.Xml
e.Layout.LoadOnDemand = LoadOnDemand.Xml
e.Layout.RowsRange = 50
e.Layout.XmlLoadOnDemandType = XmlLoadOnDemandType.Accumulative
SampleGrid.DisplayLayout.Pager.StyleMode=PagerStyleMode.QuickPages
SampleGrid.DisplayLayout.EnableInternalRowsManagement=True
SampleGrid.DisplayLayout.Pager.AllowCustomPaging=True
SampleGrid.DisplayLayout.Pager.AllowPaging = True
SampleGrid.DisplayLayout.Pager.PageSize = 50
SampleGrid.DisplayLayout.Pager.QuickPages = 5
htmlString.Append("<table cellspacing='0' cellpadding='0' style='width:100%;border:solid 1px Black;'>")
htmlString.Append("<tr>")
htmlString.Append("<td width='25%' align='right'>Viewing page [currentpageindex] of [pagecount] </td>")
htmlString.Append("<td align='center'>")
htmlString.Append("<b>[page:1:First] [prev]</b>")
htmlString.Append(" ")
htmlString.Append("[default]")
htmlString.Append(" ")
htmlString.Append("<b>[next] [page:[pagecount]:Last]</b>")
htmlString.Append(" ")
htmlString.Append("</td>")
htmlString.Append("<td width='25%' align='left' title='Enter page number and press Enter'>")
htmlString.Append("Go to:<input id='PagerGotoPageNumber' size='5' style='vertical-align:text-bottom;height:20px;font-family:verdana;font-size:8pt;padding:0 0 0 0;border:solid 1px black' onkeydown='return gotoPageKeyDown();' type='text' autocomplete='off' />")
htmlString.Append("<button style='height:22px' onclick='gotoPage();'>Go</button>")
htmlString.Append("</td>")
htmlString.Append("</tr>")
htmlString.Append("</table>")
SampleGrid.DisplayLayout.Pager.Pattern=htmlString.ToString()
End Sub
Private Sub SampleGrid_PageIndexChanged(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.UltraWebGrid.PageEventArgs) Handles SampleGrid.PageIndexChanged
SampleGrid.DisplayLayout.Pager.CurrentPageIndex = e.NewPageIndex
End Sub
With custom paging it is expected that you will provide the data for the page that you are looking to load. This is necessary because your custom paging may be implemented to have letters rather than page numbers like the example in the Infragistics help.
If you are looking to do this you would need to make the following changes:
A simple example that shows paging working with the code that you are using is:
Protected Sub UltraWebGrid1_InitializeDataSource(sender As Object, e As Infragistics.WebUI.UltraWebGrid.DataSourceEventArgs) Handles UltraWebGrid1.InitializeDataSource
Me.UltraWebGrid1.DisplayLayout.Pager.PageCount = 4
Me.UltraWebGrid1.DataSource = Me.GetEmployees(Me.UltraWebGrid1.DisplayLayout.Pager.CurrentPageIndex)
End Sub
Private Function GetEmployees(page As Integer) As DataTable
Dim dtData As DataTable = New DataTable("Employees")
dtData.Columns.Add("EmployeeID", GetType(Integer))
dtData.Columns.Add("Name", GetType(String))
dtData.Columns.Add("OnSite", GetType(Boolean))
dtData.Columns.Add("DateOfHire", GetType(DateTime))
dtData.Columns.Add("Department", GetType(Integer))
For i As Integer = (page - 1) * 50 To (page - 1) * 50 + 50 Step 1
dtData.Rows.Add(New Object() {i, String.Format("Name {0}", i), (i Mod 2 = 0), DateTime.Today, i Mod 8})
Next
Return dtData
End Function
'Protected Sub UltraWebGrid1_PageIndexChanged(sender As Object, e As Infragistics.WebUI.UltraWebGrid.PageEventArgs) Handles UltraWebGrid1.PageIndexChanged
' Me.UltraWebGrid1.DisplayLayout.Pager.CurrentPageIndex = e.NewPageIndex
'End Sub
Note that you may not need to use custom paging, if you set DisplayLayout.AllowCustomPaging to false then the grid would handle the paging automatically when you click the first,prev, numbers, next and last options in the pager. This would also allow you to keep your data as is and not have to also manually handle sorting and filtering. If you do this you would still remove the PageIndexChanged handler.
Note that then for the go to button after the input, you would likely need to set the page in JavaScript which can be done with the goToPage client side method of the WebGrid.
While it isn't related to the issue that you are having, setting EnableInternalRowsManagement to true has no affect when using InitializeDataSource to set the DataSource of the WebGrid.