How to print full contents of radgrid with scrolling enabled?

10 posts, 0 answers
  1. Kimberly
    Kimberly avatar
    6 posts
    Member since:
    Jul 2012

    Posted 13 Nov 2012 Link to this post

    Hi!

    I am fairly new to using telerik controls.  I would like to be able to print the full contents of a radgrid that has scrolling enabled.  I found the following post http://www.telerik.com/community/forums/aspnet-ajax/grid/print-radgrid-contents.aspx I am able to print just the contents of the radgrid that has been rendered client side even if I am able to turn off the scrollbar.  I was able to get the count of the number of the rows and saw that they were what I was expecting but only the first 15 or so rows were being printed.  I also tried to accomplish this server side by turning off the scrolling and calling

    ScriptManager

     

     

    .RegisterStartupScript(this.Page, this.GetType(), "printRADGrid", "PrintRadGrid();", true);

     

     but the contents of my radgrid seems to be null.  I am also using master pages.  I have spent a while trying to find an easy solution and haven't been very successful.  Can someone please point me in the right direction?  Thanks in advance for your help! 
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 16 Nov 2012 Link to this post

    Hi Kimberly,

    I suppose you have paging switched on. If this is the case, just set AllowPaging = false for the MasterTableView on the server, then call the grid's Rebind() method and then register your start up script.


    Regards, Tsvetoslav
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kimberly
    Kimberly avatar
    6 posts
    Member since:
    Jul 2012

    Posted 16 Nov 2012 Link to this post

    Tsvetoslav,

    Thank you for your reply!  I am not sure that I understand your comments completely.  Can you provide me with more information?  As I explained earlier, I am fairly new to telerik controls.  I have a radgrid with scrolling enabled.  I do not use paging so I do not have any settings to enable or disable that option.  Initially, I tried to use the following javascript code listed below client side to print out the full contents of my radgrid but it only printed out the contents of the radgrid that were rendered with the scrollbar (i.e. the first 15 or so records).  I couldn't really get it to work right when trying to remove the scrollbar since not all of the records were listed. 


    function getOuterHTML(object) {
          var element;
          if (!object) return null;
          element = document.createElement("div");
          element.appendChild(object.cloneNode(true));
          return element.innerHTML;
        }

    function PrintRadGrid() {
      
    var previewWnd = window.open('about:blank', '', '', false);
      
    var sh = '<%= ClientScript.GetWebResourceUrl(rgDisplayQueryLogResults.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",rgListAllAccounts.Skin)) %>';
      
    alert("sh" + sh); 
      
    var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
      
    var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= rgDisplayQueryLogResults.ClientID %>').get_element()) + "</body></html>";
      
    previewWnd.document.open();
      
    previewWnd.document.write(htmlcontent);
      
    previewWnd.document.close();
      
    previewWnd.print();
      
    previewWnd.close();
      
    }

    I then tried to do this server side by disabling the scrolling and maxing out the width and height.  But it doesn't seem to work either as my radgrid is null in the PrintRadGrid javascript function.    I had this working initally with a gridview and a div with overflow hidden or shown but I would really like to get this working with my radgrid since it would be simplier to maintain.  Please let me know if you need for me to provide you with any other information.  Thanks in advance for your help!

    protected void listAllAcctsBtnPrinterFriendlyFormat_Click(object sender, EventArgs e)
        {
          rgDisplayQueryLogResults.ClientSettings.Scrolling.AllowScroll = false;
          rgDisplayQueryLogResults.MasterTableView.Width = Unit.Percentage(100);
          rgDisplayQueryLogResults.MasterTableView.Height = Unit.Percentage(100);
          ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "printRADGrid", "PrintRadGrid();", true);
    }//end of listAllAcctsBtnPrinterFriendlyFormat_Click


    <asp:UpdatePanel runat="server" ID="upQueryLogsResults" Visible="false">
          <ContentTemplate>
            <telerik:RadGrid ViewStateMode="Enabled" ID="rgDisplayQueryLogsResults" DataSourceID="sdsQueryLogs"
              ShowFooter="False" GridLines="None" AllowSorting="True" Width="950px" runat="server"
              AutoGenerateColumns="false" >
              <MasterTableView Width="100%" EnableNoRecordsTemplate="true">
                <NoRecordsTemplate>
                  There is no data that matches your query criteria. Please try again.</NoRecordsTemplate>
                <Columns>
                  <telerik:GridBoundColumn UniqueName="UpdatedDate" DataField="UpdatedDate" HeaderText="Date"
                    SortExpression="UpdatedDate" HeaderStyle-Width="80px" DataType="System.DateTime"
                    DataFormatString="{0:d}" HtmlEncode="true" />
                  <telerik:GridBoundColumn UniqueName="UpdatedBy" DataField="UpdatedBy" HeaderText="User ID"
                    SortExpression="UpdatedBy" HeaderStyle-Width="100px" HtmlEncode="true" />
                  <telerik:GridBoundColumn UniqueName="FullName" DataField="FullName" HeaderText="Full Name"
                    SortExpression="FullName" HeaderStyle-Width="150px" />
                  <telerik:GridBoundColumn UniqueName="AccountIDNumber" DataField="AccountIDNumber"
                    HeaderText="Account Number" SortExpression="AccoundIDNumber" HeaderStyle-Width="100px" HtmlEncode="true" />
                  <telerik:GridBoundColumn UniqueName="Description" DataField="Description" HeaderText="Description"
                    SortExpression="FullName" HeaderStyle-Width="400px" htmlencode="true"/>
                </Columns>
              </MasterTableView>
              <HeaderStyle Width="200px" HorizontalAlign="Center" />
              <ClientSettings EnableRowHoverStyle="true">
                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                </Scrolling>
              </ClientSettings>
              <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
                <Pdf AllowCopy="true" AllowModify="true" AllowPrinting="true" PageHeight="300mm"
                  PageWidth="250mm" />
              </ExportSettings>
            </telerik:RadGrid>
          </ContentTemplate>
        </asp:UpdatePanel>
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 21 Nov 2012 Link to this post

    Hi Kimberly,

    Try adding the following line before getting the outer html of the grid:
    $find('<%= rgDisplayQueryLogResults.ClientID %>').GridDataDiv.style.height = "100%";


    Regards, Tsvetoslav
    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.
  6. Kimberly
    Kimberly avatar
    6 posts
    Member since:
    Jul 2012

    Posted 26 Nov 2012 Link to this post

    Tsvetoslav,

    Thank you for your reply!  It looks like I am getting closer but am seeing some unusual behavior when I actually print the contents.  I am seeing the header of the radgrid on one page, 30 records on another page, and the bottom of the radgrid on the 3rd page.  I do not see the scrollbar on the side of the radgrid but in the browser window.  Do you know what else I might be missing?  Please let me know if you need for me to provide you with any other information.

    Thanks!!

    Kim 
  7. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 29 Nov 2012 Link to this post

    Hi Kimberley,

    In this case, the best approahc is just to swith of scrolling before printing the contents of the grid. Attached is a small sample.


    Regards, Tsvetoslav
    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.
  8. Kimberly
    Kimberly avatar
    6 posts
    Member since:
    Jul 2012

    Posted 29 Nov 2012 Link to this post

    Tsvetoslav,

    Thank you for your reply!  Your code does not work for me.  I tried to do this originally when I first posted.  When the PrintRadScript function is called, my radgrid seems to be null for some reason.  In the previous code that you had me try, do you know why I could see all of the entries but only the first couple were printed?  The scrollbar was on the IE page and I could see that the scrollbar was no longer listed on the contents of the new page.  It just seems odd that I can see the full contents of the radgrid in the new page but I am not able to print them.  Please let me know if you need for me to provide you with any other information.

    Thanks!!

    Kim
  9. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 30 Nov 2012 Link to this post

    Hello Kimberly,

    Yes, please, open up a formal support ticket and send a runnable sample with your grid - we shall modify it to demonstrated how to print it if that's possible. Thanks in advance.


    Greetings, Tsvetoslav
    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.
  10. Erez
    Erez avatar
    1 posts
    Member since:
    Jun 2014

    Posted 13 Jul Link to this post

    Hi,

    Did someone find the solution to above problem? I also can't print all the records of the grid when paging is On.

    thanks,

  11. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 14 Jul Link to this post

    Hi Erez,

    You should manually disable the paging before calling print() for the RadGrid as the printing functionality by default prints only the current view.

    Regards,
    Maria Ilieva
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017