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

RadGrid PAging not working with clienside (pageMethod) binding

1 Answer 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Somnath
Top achievements
Rank 1
Somnath asked on 28 Jan 2013, 07:05 AM
Hi ,

I am strange issue in particular page.
I am using client side binding using following tag
        <DataBinding Location="~/ReportManagement/ReportDesigner.aspx" SelectMethod="wmBindSecurity" />
After page load 10 records display properly, but in pagination bar page number is missing ,and also it is written 0 items in 0 pages.
and page size changing works perfectly.


On change of next or prev request is not going to server side.

Please help me .
I am using following code.

ASPX
<telerik:RadGrid ID="rgSecurity" runat="server" AllowPaging="true" AllowMultiRowSelection="True"
                           GridLines="None" AllowSorting="true" Width="99%">
                           <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
                           <ItemStyle Wrap="false" />
                           <HeaderStyle Wrap="false" />
                           <ClientSettings EnableRowHoverStyle="true" AllowColumnsReorder="true" AllowColumnHide="true"
                               Resizing-AllowColumnResize="true" Resizing-EnableRealTimeResize="true" ReorderColumnsOnClient="true">
                               <Resizing ResizeGridOnColumnResize="true" ClipCellContentOnResize="false" />
                               <DataBinding Location="~/ReportManagement/ReportDesigner.aspx" SelectMethod="wmBindSecurity" />
                               <Selecting AllowRowSelect="true" />
                               <ClientEvents OnRowSelected="RowSelected" OnRowDeselected="RowSelected" OnDataBindingFailed="rgSecurity_OnDataBindingFailed">
                               </ClientEvents>
                           </ClientSettings>
                           <MasterTableView AutoGenerateColumns="false" AllowNaturalSort="false" ClientDataKeyNames="Id"
                               CommandItemDisplay="Top">
                               <CommandItemTemplate>
                                   <telerik:RadToolBar ID="rtbSecurity" runat="server" Height="26px" Width="100%" ClientIDMode="Static"
                                       OnClientButtonClicking="rtbSecurity_onToolBarClientButtonClicking">
                                       <Items>
                                           <telerik:RadToolBarButton Text="Add" ImageUrl="~/Images/NewEnable2.png" runat="server"
                                               ClientIDMode="Static" Value="Add" CommandName="Add" CssClass="RadToolBar">
                                           </telerik:RadToolBarButton>
                                           <telerik:RadToolBarButton Text="Remove" ImageUrl="~/Images/imgDelBtnEnable.png" runat="server"
                                               ClientIDMode="Static" Value="Delete" CommandName="Delete" CssClass="RadToolBar"
                                               Enabled="false">
                                           </telerik:RadToolBarButton>
                                       </Items>
                                   </telerik:RadToolBar>
                               </CommandItemTemplate>
                               <Columns>
                                   <telerik:GridClientSelectColumn UniqueName="column" HeaderStyle-Width="35px" ItemStyle-Width="35px"
                                       Resizable="false">
                                   </telerik:GridClientSelectColumn>
                                   <telerik:GridTemplateColumn UniqueName="Name" HeaderText="Name" SortExpression="Name"
                                       ShowSortIcon="true" ItemStyle-Wrap="false">
                                       <ClientItemTemplate>
                                           <label id="aName_#=Id#" border="0"  #=Type == 0 ? "style='background: url(../Images/usersetting.png) top left no-repeat !important;padding-left:18px'" :  "style='background: url(../Images/user-groups.png) top left no-repeat !important;padding-left:18px'"#>#=Name#</label>
                                       </ClientItemTemplate>
                                       <ItemStyle Wrap="false" />
                                       <HeaderStyle Wrap="false" />
                                   </telerik:GridTemplateColumn>
                                   <telerik:GridTemplateColumn UniqueName="AllowRead" HeaderText="Read" SortExpression="AllowRead"
                                       ShowSortIcon="true" HeaderStyle-Width="10%" ItemStyle-Width="10%">
                                       <ClientItemTemplate>
                                           <input type="checkbox" id="chk_read_#=Id#" #=AllowRead == true ? "checked" : "" # #=AllowWrite == true ? "disabled" : "" # onclick="javascript:OnChangeSecurity('#=Id#','#=Type#')"/>
                                       </ClientItemTemplate>
                                   </telerik:GridTemplateColumn>
                                   <telerik:GridTemplateColumn UniqueName="AllowWrite" HeaderText="Write" SortExpression="AllowWrite"
                                       ShowSortIcon="true" HeaderStyle-Width="15%" ItemStyle-Width="15%">
                                       <ClientItemTemplate>
                                             <input type="checkbox" id="chk_write_#=Id#" #=AllowWrite == true ? "checked" : "" # onclick="javascript:OnChangeSecurity('#=Id#','#=Type#')"/>
                                       </ClientItemTemplate>
                                   </telerik:GridTemplateColumn>
                               </Columns>
                           </MasterTableView>
                       </telerik:RadGrid>


JS

function RowSelected(rowObject, args) {

            if (args != null)
                gridEventArg = args;

            var length = $find(rgSecurity_id).get_selectedItems().length;
            var radGrid = $get(rgSecurity_id);
            var radToolBar = $telerik.findControl(radGrid, "rtbSecurity");
            var addButton = radToolBar.get_items().getItem(0);
            var removeButton = radToolBar.get_items().getItem(1);
            switch (parseInt(length)) {
                case 0:
                    addButton.set_enabled(true);
                    removeButton.set_enabled(false);
                    break;
                case 1:
                    addButton.set_enabled(false);
                    removeButton.set_enabled(true);
                    break;
                default:
                    addButton.set_enabled(false);
                    removeButton.set_enabled(true);
                    break;
            }
        }
[WebMethod]
       public static Dictionary<string, object> wmBindSecurity(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression)
       {
           if (HttpContext.Current.Session["UserName"] == null)
               throw new Exception("SESSION_TIMEOUT");
 
           Dictionary<string, object> data = new Dictionary<string, object>();
 
           if (HttpContext.Current.Session["AnalystFile"] == null)
               throw new Exception("SESSION_TIMEOUT");
 
           List<SQCUser> allUsers = SQCUserList.GetUserList();
 
           List<SQCUserGroup> allGroups = SQCUserGroupList.GetGroupList();
 
           List<SQCUserGroupResourceMapping> lstUserGroupResourceMapping = ((SQWAnalystFile)HttpContext.Current.Session["AnalystFile"]).UserGroupReportMapping;
 
           List<SQCUserResourceMapping> lstUserResourceMapping = ((SQWAnalystFile)HttpContext.Current.Session["AnalystFile"]).UserReportMapping;
 
           List<SQCUser> oUsers = SQCUserList.GetUserList();
 
           var oData = lstUserGroupResourceMapping.Select(o => new
           {
               Id = o.GroupId,
               Name = allGroups.Find(g => g.GroupId == o.GroupId).GroupName,
               Type = "User Group",
               AllowRead = o.AllowRead,
               AllowWrite = o.AllowWrite
           }).ToList();
 
           oData.AddRange(lstUserResourceMapping.Select(p => new
           {
               Id = p.UserId,
               Name = SQCUserList.GetUserByUserID(p.UserId).UserName,
               Type = "User",
               AllowRead = p.AllowRead,
               AllowWrite = p.AllowWrite
           }).ToList());
 
           if (oData.Count > 0)
                data.Add("Data", oData.Skip(startRowIndex).Take(maximumRows));              
           else
               data.Add("Data", new List<SQCUserGroupResourceMapping>());
           data.Add("Count", 0);
           return data;
 
       }

Thanks & Regards ,
Somnath 

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 31 Jan 2013, 10:50 AM
Hi Somnath,

In order to resolve your issue you could modify the value of the "Count" key in the returned dictionary because the value is used to determine what to show in the pager. The value should equal the total count of items in the data source. You could take a look at the code provided below. 
data.Add("Count", oData.Count());


All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
General Discussions
Asked by
Somnath
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or