Print only data of grid

10 posts, 2 answers
  1. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 07 Jun 2010 Link to this post

    Hi,

    I am printing a grid using the following code. But it prints the entire grid with search header and Delete image of the grid. Is there any way that I avoid search header and Delete column from the grid just on print page. Following is my code. Also in below code I had to use documnet.getelementbyid commnad to find the grid because $find is not working for me.


    function

     

    PrintRadGrid(radGridId){

     

     

    var radGrid = document.getElementById(radGridId);

     

     

    var sh = '<%= ClientScript.GetWebResourceUrl(rgrdUser.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",rgrdUser.Skin)) %>';

     

     

    var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";

     

     

    var htmlcontent = styleStr + "<body>" + radGrid.outerHTML + "</body></html>";

     

    previewWnd.document.open();

    previewWnd.document.write(htmlcontent);

    previewWnd.document.close();

    previewWnd.print();

     

     

     

     

     

     

    }


    Thanks,
    Lubna.

  2. Answer
    Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 07 Jun 2010 Link to this post

    Hello Lubna,

    You could hide the desired elements (columns, items) on the server:
    protected void  LinkButton1_Click(object sender, EventArgs e)
    {
        foreach (GridItem item in radGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Pager, GridItemType.FilteringItem }))
            item.Display = false;
        radGrid1.MasterTableView.GetColumn("DeleteColumn").Visible = false;
        RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + radGrid1.ClientID + "')");
    }

    function PrintRadGrid(radGrid)
    {
        setTimeout(function ()
        {
            ....
            window.location.href = window.location.href;
        }, 100);
    }

    Regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 07 Jun 2010 Link to this post

    Thanks Daniel. This works.
  4. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 07 Jun 2010 Link to this post

    Hi Daniel,

    When I try to export grid to pdf it shows all hte columns except the last one. I tried to make it visible true explicitly but still its not showing the last column. Also the font style is not working. Following is the code.

    protected

     

    void btnPDF_Click(object sender, EventArgs e)

     

    {

    rgrdUser.MasterTableView.ExportToPdf();

     

    }


    public

     

    void ConfigurePDF()

     

    {

    rgrdUser.ExportSettings.ExportOnlyData =

    true;

     

    rgrdUser.ExportSettings.IgnorePaging =

    true;

     

    rgrdUser.ExportSettings.OpenInNewWindow =

    true;

     

    rgrdUser.Columns.FindByUniqueName(

    "DeleteColumn").Display = false;

     

    rgrdUser.Columns.FindByUniqueName(

    "ClientSelectColumn").Display = false;

     

     

    rgrdUser.Columns.FindByUniqueName("Approved").Display = true;

     

     

    foreach (GridDataItem item in rgrdUser.Items)

     

    {

    item.Style[

    "font-size"] = "4px";

     

    item.Style[

    "font-family"] = "Arial Unicode MS"; //Set UNICODE font

     

    item.Style[

    "text-align"] = "center";

     

    item.Style[

    "background-color"] = "red";

     

    }

    }

    Thanks,
    Lubna.

  5. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 09 Jun 2010 Link to this post

    Hello Lubna,

    Regarding the columns: Please try to use the Visible property instead of Display. Also I recommend that you try to export from another browser - Mozilla Firefox for instance.

    As to the font-related problem: Try to replace Arial Unicode MS with Courier New and let me know whether the font is applied properly.

    Kind regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 10 Jun 2010 Link to this post

    Hi Daniel,

    Thanks for the reply. I think, in this case displaying of column is nothing to do with its visiible property. I just removed 1 column from the grid wihle exporting to pdf and it showed me the last column. Actually the width of grid is larger than the page. How can I adjust the page size of a pdf file.

    Regards,
    Lubna.
  7. Answer
    Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 10 Jun 2010 Link to this post

    Hello Lubna,

    There is strange behavior in IE which triggers when you have a col element that with visibility="hidden" - that is why I suggested that you use Visible="false" instead of Display="false" when hiding RadGrid columns.

    As to the page width - please examine the following link:
    PDF export

    Regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 11 Jun 2010 Link to this post

    Hi Daniel,

    The link solved the problem.

    Regrads,
    Lubna.
  9. Nguyen Huu
    Nguyen Huu avatar
    5 posts
    Member since:
    Jun 2019

    Posted 25 Jun 2019 in reply to Daniel Link to this post

    I have been put  hide the desired elements (columns, items) on the server:

    protected void  LinkButton1_Click(object sender, EventArgs e)
    {
        foreach (GridItem item in radGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Pager, GridItemType.FilteringItem }))
            item.Display = false;
        radGrid1.MasterTableView.GetColumn("DeleteColumn").Visible = false;
        RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + radGrid1.ClientID + "')");
    }

    however after i have closed the print window then the values as GridItemType.Pager, GridItemType.FilteringItem, GridItemType.CommandItem is not display again. How can I do fix it?

  10. Peter Milchev
    Admin
    Peter Milchev avatar
    804 posts

    Posted 28 Jun 2019 Link to this post

    Hello Nguyen,

    The Grid needs a postback in order to have enable/disable paging, so an additional postback is required to restore the paging. 

    Another option that would not require the additional postback is if you create and add another Grid with the same data and settings but with no Paging enabled, just for printing purposes. Then, once you call the printing function, you can hide this grid visually and set its Visible=false property on the next postback.

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top