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

RadGrid PagerStyle

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Monte
Top achievements
Rank 1
Monte asked on 25 Jul 2013, 09:31 PM
We have a request to hide the page numbers and the page size but not the PagerTextFormat when the amount of records is less than the pagesize itself.  In other words, if there are 7 records but the minimum PageSize is 10, the Page Count and the Page Mode should not be visible.  And changing the PagerStyle AlwaysVisible to False hides everything.  

Can this be done without using CSS display none to all elements in the Pager Style?

Thank you,
Julio

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Jul 2013, 05:43 AM
Hello,

<script type="text/javascript">
        
 
            function hidepager() {
                $(".rgArrPart1").css("display", "none");
                $(".rgNumPart").css("display", "none");
                $(".rgArrPart2").css("display", "none");
                $(".rgAdvPart").css("display", "none");
            }
 
            function showPager() {
                $(".rgArrPart1").css("display", "");
                $(".rgNumPart").css("display", "");
                $(".rgArrPart2").css("display", "");
                $(".rgAdvPart").css("display", "");
            }
 
        </script>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
 
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
        AllowPaging="true" PageSize="20" OnItemCreated="RadGrid1_ItemCreated" OnItemEvent="RadGrid1_ItemEvent"
        OnPreRender="RadGrid1_PreRender">
        <PagerStyle AlwaysVisible="true" />
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data1 = new[] {
               new { ID = 1, Name ="Name_1"},
               new { ID = 2, Name = "Name_2"},
               new { ID = 3, Name = "Name_3"},
               new { ID = 4, Name = "Name_4"},
               new { ID = 5, Name = "Name_5"}
           };
 
        RadGrid1.DataSource = data1;
    }
 
    private int totalItemCount;
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
 
    }
    protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
    {
        if (e.EventInfo is GridInitializePagerItem)
        {
            totalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
        }
    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (totalItemCount <= RadGrid1.MasterTableView.PageSize)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "test123", "hidepager();", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "test123", "showPager();", true);
             
        }
    }


Thanks,
Jayesh Goyani
0
Monte
Top achievements
Rank 1
answered on 29 Jul 2013, 07:09 PM
Jayesh;

Thank you for your response.  We were hoping to not have to do it with CSS but it seems that it may be the easiest way.  The script manager syntax that you provided did not work for us since it did not fire on postback.  We modified it to use: 
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "HidePager", "hidepager();", true);
and it worked great.

Again, thank you for your help.

Julio
Tags
Grid
Asked by
Monte
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Monte
Top achievements
Rank 1
Share this question
or