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

Telerik RadGrid: Paging is not working properly with Filtering.

2 Answers 229 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thanh Sang
Top achievements
Rank 1
Thanh Sang asked on 28 May 2014, 05:07 PM
I am using RadGrid which has both Filter and Pager.
When filtered 3 pages after that I clicked on page 2 then radgrid show page 2 of all data (filter not working at this time)
Sometimes, Filter also did not work properly. I don't know why. Can someone help me now?
_fileRadGrid.MasterTableView.FilterExpression always = empty so I have to use _fileStatusPendingRadGrid.MasterTableView.GetColumnSafe("Status").CurrentFilterValue to check HasFilter.

When I reload the page then pager and filter are not working properly. (I also code for another web app with filter and pager are working fine)
Please tell me why that code not working? the version of telerik is 2014.1.225.45

Inline:
<telerik:RadGrid ID="_fileRadGrid" runat="server" AutoGenerateColumns="False" AllowSorting="False"  
        AllowPaging="true" AllowFilteringByColumn="True" EnableAJAX="True" EnableViewState="True" ViewStateMode="Enabled"
        EnableEmbeddedSkins="False" EnableEmbeddedBaseStylesheet="False" Skin="NitroCleo" PageSize="10" EnableLinqExpressions="False"
        OnNeedDataSource="FileNeedDataSource"
        OnItemDataBound="FileItemDataBound">        
        <ClientSettings>
            <clientevents ongridcreating="OnGridCreated"/>
        </ClientSettings>
        <MasterTableView DataKeyNames="FileIdentifier" ClientDataKeyNames="FileIdentifier"
            NoMasterRecordsText="No file" AllowFilteringByColumn="True" >
            <PagerStyle Mode="NextPrevAndNumeric" PageButtonCount="6" />
            <Columns>
                <telerik:GridTemplateColumn HeaderStyle-Width="25px" AllowFiltering="False">
                    <ItemTemplate>
                        <asp:Label ID="_iconLabel" runat="server"></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Status" UniqueName="Status" DataField="Status" AutoPostBackOnFilter="True"
                    CurrentFilterFunction="Contains">
                    <ItemTemplate>
                        <asp:HyperLink runat="server" ID="_statusLink"></asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

Code Behind:
        protected void FileNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            BindFileGrid(true);            
        }

        private void BindFileGrid(bool needDataBind = false)
        {
            var listFile = new List<FileItem>();
            int virtualItemCount = 0;
            int pageSize = 0;
            int pageIndex = 0;

            try
            {
                if (!HasApplyFilter())
                {
                    pageSize = _fileRadGrid.PageSize;
                    pageIndex = _fileRadGrid.CurrentPageIndex;
                }
                _fileRadGrid.AllowCustomPaging = !HasApplyFilter();

                listFile = GetDataSourceForFile(pageIndex, pageSize, out virtualItemCount);
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("An error while get file. Error: {0}", ex.Message));
            }
            
            _fileRadGrid.MasterTableView.PagerStyle.AlwaysVisible = virtualItemCount == 0 ? false : true;    

            if (listFile != null)
            {
                _fileRadGrid.DataSource = listFile;
                _fileRadGrid.VirtualItemCount = virtualItemCount;

                if (!needDataBind)
                {
                    _fileRadGrid.DataBind();
                }
            }
        }

Thanks for your reading!

2 Answers, 1 is accepted

Sort by
0
Thanh Sang
Top achievements
Rank 1
answered on 29 May 2014, 02:32 AM
Hello! Can someone help me?
0
Pavlina
Telerik team
answered on 30 May 2014, 03:32 PM
Hello,

You should never call DataBind() method when using advanced data-binding through NeedDataSource. Please refer to the links below for more information:
http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html

Regards,
Pavlina
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
Thanh Sang
Top achievements
Rank 1
Answers by
Thanh Sang
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or