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

How to print full contents of radgrid with scrolling enabled?

9 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kimberly
Top achievements
Rank 1
Kimberly asked on 13 Nov 2012, 10:20 PM
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! 

9 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 16 Nov 2012, 06:29 AM
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.
0
Kimberly
Top achievements
Rank 1
answered on 16 Nov 2012, 05:08 PM
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>
0
Tsvetoslav
Telerik team
answered on 21 Nov 2012, 12:48 PM
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.
0
Kimberly
Top achievements
Rank 1
answered on 26 Nov 2012, 10:59 PM
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 
0
Tsvetoslav
Telerik team
answered on 29 Nov 2012, 02:04 PM
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.
0
Kimberly
Top achievements
Rank 1
answered on 29 Nov 2012, 09:18 PM
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
0
Tsvetoslav
Telerik team
answered on 30 Nov 2012, 09:20 AM
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.
0
Erez
Top achievements
Rank 1
answered on 13 Jul 2016, 06:13 PM

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,

0
Maria Ilieva
Telerik team
answered on 14 Jul 2016, 12:27 PM
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.
Tags
Grid
Asked by
Kimberly
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Kimberly
Top achievements
Rank 1
Erez
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or