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

CurrentPageIndex not updating right away

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Beth M
Top achievements
Rank 1
Beth M asked on 21 Jun 2010, 07:46 PM
Hi,
I'm trying to implement virtual scrolling, and it's working great, except that the currentpageindex doesn't update immediately..  I open the page, and it loads page 0.  Then I scroll down, the loading symbol shows, it displays data - same data as page 0.  If I hit 'refresh', it then loads the correct data.  Or, if I scroll down another page (so now the pager says I'm on page 2) it updates and shows me the page 1 data - it's one page behind.  Did I miss a rebind call?  I'm using NeedDataSource, though, and so I don't need to put that in there, right?

Here's my radgrid tag:

<telerik:RadGrid 
    id="RadGrid1" 
    runat="server" 
    ShowGroupPanel="True" 
    GridLines="None" 
    PageSize="20" 
    AllowPaging="True" 
    AllowCustomPaging="True" 
    AllowSorting="True" 
    GroupingEnabled="True" 
    Height="625px" 
    EnableViewState="True" 
    > 
    <PagerStyle Mode="NumericPages" /> 
    <MasterTableView 
        DataKeyNames="id_col" 
        AllowMultiColumnSorting="True" 
        AutoGenerateColumns="False" 
        CommandItemDisplay="Top" 
        ShowHeadersWhenNoRecords="True" 
        ShowFooter="true" 
        > 
        <CommandItemSettings ShowAddNewRecordButton="False"></CommandItemSettings> 
        <Columns> 
            <telerik:GridBoundColumn Visible="False" DataField="name" HeaderText="Name" UniqueName="name"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn Visible="False" DataField="classname" HeaderText="Class Name" UniqueName="classname"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn Visible="False" DataField="identifier" HeaderText="Identifier" UniqueName="identifier"></telerik:GridBoundColumn> 
        </Columns> 
    </MasterTableView> 
    <GroupingSettings ShowUnGroupButton="True"></GroupingSettings> 
    <SortingSettings SortToolTip="name" /> 
    <ClientSettings AllowDragToGroup="true"
            <Scrolling 
                AllowScroll="True" 
                EnableVirtualScrollPaging="True" 
                UseStaticHeaders="True" 
                SaveScrollPosition="True" /> 
    </ClientSettings> 
</telerik:RadGrid> 
 

And my vb NeedDataSource function:
Protected Sub RadGrid1_NeedDataSource(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
    Dim sql As String 
    Dim cmd As OracleCommand 
    Dim row_count As Integer = 1 
     
    ' Open connection 
    conn.Open() 
 
    ' Set up sql command 
    sql = "db_search" 
    cmd = New OracleCommand(sql, conn) 
    cmd.CommandType = CommandType.StoredProcedure 
 
    ' Add parameters 
    cmd.Parameters.Add("row_start", OracleDbType.Decimal, RadGrid1.CurrentPageIndex * RadGrid1.PageSize, ParameterDirection.Input) 
    cmd.Parameters.Add("row_end", OracleDbType.Decimal, (RadGrid1.CurrentPageIndex + 1) * RadGrid1.PageSize, ParameterDirection.Input) 
    cmd.Parameters.Add("db_cur", OracleDbType.RefCursor, ParameterDirection.Output) 
     
    ' Get row count (cut out this part for brevity, it does update it though) 
    Me.RadGrid1.VirtualItemCount = row_count 
 
    ' Set as the datasource 
    Dim da As New OracleDataAdapter(cmd) 
    Dim ds As New DataSet() 
    da.Fill(ds) 
    Me.RadGrid1.DataSource = ds 
 
    ' Cleanup 
    da.Dispose() 
    ds.Dispose() 
    conn.Close() 
End Sub 

I looked at this thread but it did not fix my issue, as well as various documentation for paging and virtual scrolling, and haven't found a solution yet.  Thanks in advance for any advice!


1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 24 Jun 2010, 08:50 AM
Hello Beth M,

I have tried the code bellow and it works as expected on my side. My suggestion is to open a formal support ticket and send us a runnable sample that demonstrates your scenario. This way we would be able to track the cause of the issue and provide you with more to-the-point resolution.

Markup:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Vista" />
<telerik:RadGrid ID="RadGrid1" Skin="Vista" runat="server" PageSize="15" AllowPaging="True"
    AllowCustomPaging="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource">
    <PagerStyle Mode="NumericPages" />
    <MasterTableView AutoGenerateColumns="False">
        <Columns>
            <telerik:GridBoundColumn DataField="Col1" HeaderText="Col1" UniqueName="Col1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Col2" HeaderText="Col2" UniqueName="Col2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Col3" HeaderText="Col3" UniqueName="Col3">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="True" EnableVirtualScrollPaging="True" UseStaticHeaders="True"
            SaveScrollPosition="True" />
    </ClientSettings>
</telerik:RadGrid>

Code behind:

private DataTable GetDataTable()
{
    DataTable table;
    if (ViewState["Table"] == null)
    {
        table = new DataTable();
        table.Columns.Add("Col1", typeof(int));
        table.Columns.Add("Col2");
        table.Columns.Add("Col3");
        for (int i = 0; i < 1000; i++)
        {
            table.Rows.Add(i, "Col2", "Col3" + i);
        }
        ViewState["Table"] = table;
    }
    else
    {
        table = ViewState["Table"] as DataTable;
    }
    return table;
}
 
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    RadGrid1.VirtualItemCount = 1000;
    DataSet dataSet = new DataSet();
    RadGrid1.DataSource = GetDataTable().Select("Col1 >= " + ((RadGrid1.CurrentPageIndex * RadGrid1.PageSize)) + " AND Col1 <" + ((RadGrid1.CurrentPageIndex + 1) * RadGrid1.PageSize));
}

Regards,
Martin
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
Tags
Grid
Asked by
Beth M
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or