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

Print whole Radgrid from ClientSide during print

7 Answers 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Srini
Top achievements
Rank 1
Srini asked on 23 Nov 2010, 07:16 PM

Hi,

I have a asp.net page( .aspx) with user control( .ascx). That user control has a RADGrid with several records with paging turned on.
When We want to print, we would like to print all rows( not just rows of current page showing in the grid).
Currently, when we print, it is printing only the rows from page that is being shown on the grid on the screen.
To solve the problem, we wanted to hookup onBeforePrint and set the page size to max number of rows and revertback during onafterprint event
. For that we have the following client-side javascript function. But the effect on RADGrid is not happening until after we get
the print dialog and click on the print dialog. We would like to know how to make the RADGrid display all rows before
the print dialog so that print process would pick up the grid with all rows.

We are wondering how we can do this without going to server and disable the paging through Ajax.

<script type="text/javascript">

    var pageSize;
    var  PageCount;
    function disableGridPaging()
    {       
        var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
        pageSize = grid.MasterTableView.PageSize;
        PageCount = grid.MasterTableView.PageCount;
        grid.MasterTableView.beginUpdate();
        grid.MasterTableView.set_pageSize(grid.MasterTableView.PageSize * grid.MasterTableView.PageCount);
        grid.MasterTableView.endUpdate();
    }

    function revertBackGridPaging()
    {
        var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
        grid.MasterTableView.beginUpdate();
        grid.MasterTableView.set_pageSize(pageSize);
        grid.MasterTableView.endUpdate();
    }

     window.onbeforeprint = disableGridPaging
     window.onafterprint = revertBackGridPaging
</script>

thanks,
Srini

7 Answers, 1 is accepted

Sort by
0
Srini
Top achievements
Rank 1
answered on 23 Nov 2010, 08:37 PM

We also tried the server AJAX event approach that was suggested in another post.

On the client we have the following:

Javascript:
-----------
<script type="text/javascript" language="javascript">
    function disableGridPaging()
    {
        var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
        grid.get_masterTableView().fireCommand("DisablePaging", "");
    }

    function revertBackGridPaging()
    {
        var grid = $find("<%= RadGrid_ContactDetails.ClientID %>");
        grid.get_masterTableView().fireCommand("EnablePaging", "");
    }

    window.onbeforeprint=disableGridPaging
    window.onafterprint = revertBackGridPaging

</script>

GRID:
-----
<ClientNet:ClientNetRadGrid ID="RadGrid_ContactDetails" runat="server" EnableMouseOver="false"
    AutoGenerateColumns="false" AllowMultiRowSelection="false" EnableSelectColumn="false"
    DefaultColumnWidth="78" AllowPaging="false" Width="100%" Height="200px" BorderWidth="0px"
    EnableAJAXLoadingTemplate="True" EnableAJAX="True" PagerStyle-Mode="NextPrevNumericAndAdvanced"
    onitemcommand="RadGrid_ContactDetails_ItemCommand"
    CommandItemDisplay="Top"  ExcludedFormattingColumn="ContactID">

Server :
--------

            protected void RadGrid_ContactDetails_ItemCommand(object source, GridCommandEventArgs e)
            {
                if (e.CommandName == "DisablePaging")
                {
                    RadGrid_ContactDetails.AllowPaging = false;
                    RadGrid_ContactDetails.Rebind();
                }
                else if (e.CommandName == "EnablePaging")
                {
                    RadGrid_ContactDetails.AllowPaging = true;
                    RadGrid_ContactDetails.Rebind();
                }
            }

 

This approach also did not work with print/print preview. The grid is expanding only after the print event.
Wondering how to make grid expand and show all the rows before print process..

0
Dimo
Telerik team
answered on 24 Nov 2010, 02:15 PM
Hi Srini,

Unfortunately, this is not possible. Please refer to the following page for alternative solutions (exporting or disabling Paging with AJAX):

http://www.telerik.com/community/forums/aspnet/grid/72051-radgrid-print.aspx

All the best,
Dimo
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vijayaraj
Top achievements
Rank 1
answered on 17 Jun 2011, 01:58 PM
Hi,

The link is not working.

Regards,
Vijay
0
Filip
Telerik team
answered on 17 Jun 2011, 04:00 PM
Hi Vijayaraj,

Thank you for reporting this!
We have found the problem and you should be able to access the link now.

Sorry for the inconvenience!

Have a relaxing weekend,
FilipS
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ram
Top achievements
Rank 1
answered on 02 Aug 2011, 06:10 PM
Hi
I'm using radgrid.
Its working fine.
I'm able to print the radgrid.
But while printing I'm disabling the paging and scroll bar and showing the headers.
But these changes are visible to user at front end and there will be distractions till closing the print window.

I'm calling serversice ItemCreated function from client side to disable paging etc...
radGrid.get_masterTableView().fireCommand("EnablePaging", "");
javascript::
'function PrintRadGrid(radGridId, radGridId2) {
            var radGrid = $find(radGridId);
            var radgrid2=$find(radGridId2);
            var previewWnd = window.open('about:blank', '', '', false);
            var sh = '<%# ClientScript.GetWebResourceUrl(endPntGrd.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",endPntGrd.Skin)) %>';
            var sh1 = '<%# ClientScript.GetWebResourceUrl(dispatcherGrd.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",dispatcherGrd.Skin)) %>';
            var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
            var styleStr= styleStr+"<html><head><link href = '" + sh1 + "' rel='stylesheet' type='text/css'></link></head>";
            var htmlcontent = styleStr + "<body>" + radgrid2.get_element().outerHTML;
            var htmlcontent = htmlcontent+"</br>" + styleStr + radGrid.get_element().outerHTML + "</body></html>"; ;
            previewWnd.document.open();
            previewWnd.document.write(htmlcontent);
            previewWnd.document.close();
            previewWnd.print();
            previewWnd.close();
            radGrid.get_masterTableView().fireCommand("EnablePaging", "");
        }'
server side::
'protected void endPntGrd_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "EnablePaging")
        {
            endPntGrd.MasterTableView.ShowHeader = false;
            endPntGrd.MasterTableView.GetColumn("chartcolumn").Display = true;
            endPntGrd.ClientSettings.Scrolling.AllowScroll = true;
            endPntGrd.Rebind();
            dispatcherGrd.ClientSettings.Scrolling.AllowScroll = true;
            dispatcherGrd.MasterTableView.GetColumn("chartcolumn").Display = true;
            dispatcherGrd.MasterTableView.ShowHeader = false;
            dispatcherGrd.Rebind();
        }
    }'
Please can any one help me how to avoid this problem. Really its urgent for me.
Please help me
0
Pankaj
Top achievements
Rank 1
answered on 29 Apr 2013, 01:55 PM

Hi all,

I have a paged RadGrid with a print function (which is in the RadGrid by default).. it is not printing the generated report in google chrome but its working fine in all the browser , Can anybody Help to solve this problem.

Thank you in advance!

0
Eyup
Telerik team
answered on 02 May 2013, 08:03 AM
Hi Pankaj,

Please note that RadGrid is a complex script control and printing it on a single-click is not fully supported, nor tested. Nevertheless, I am attaching a sample web site to demonstrate how you can print all of the items using an open-in-window approach.

Alternatively, you can try a server-side approach:
Copy Code
Copy Code
bool isPrinting = false;
protected void Page_Init(object sender, EventArgs e)
{
    if (Session["RadGridOutput"] != null)
    {
        var output = Session["RadGridOutput"];
        // execute custom logic
        Session["RadGridOutput"] = null;
    }
}
protected void Button1_Click(object sender, EventArgs e)
{
    isPrinting = true;
    RadGrid1.AllowPaging = false;
    RadGrid1.AllowFilteringByColumn = false;
    RadGrid1.AllowSorting = false;
    RadGrid1.Rebind();
    RemoveWebControls(RadGrid1);
}
private void RemoveWebControls(Control ctrl)
{
    var q = new Stack<Control>(ctrl.Controls.OfType<Control>());
    while (q.Count > 0)
    {
        Control control = q.Pop();
        if (control is IButtonControl || control is ICheckBoxControl || control is ITextControl)
            ctrl.Controls.Remove(control);
        if (control.HasControls())
            RemoveWebControls(control);
    }
}
protected override void Render(HtmlTextWriter writer)
{
    if (isPrinting)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter strWriter = new StringWriter(sb);
        HtmlTextWriter newWriter = new HtmlTextWriter(strWriter);
        RadGrid1.RenderControl(newWriter);
        Session["RadGridOutput"] = sb.ToString();
        Response.Redirect(Request.Url.ToString());
    }
    base.Render(writer);
}
public override void VerifyRenderingInServerForm(Control control)
{
    if (!isPrinting)
        base.VerifyRenderingInServerForm(control);
}

Hope this helps.

Regards,
Eyup
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
Grid
Asked by
Srini
Top achievements
Rank 1
Answers by
Srini
Top achievements
Rank 1
Dimo
Telerik team
Vijayaraj
Top achievements
Rank 1
Filip
Telerik team
Ram
Top achievements
Rank 1
Pankaj
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or