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

Print only data of grid

9 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lubna Ansari
Top achievements
Rank 1
Lubna Ansari asked on 07 Jun 2010, 12:16 PM
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.

9 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 07 Jun 2010, 02:41 PM
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.
0
Lubna Ansari
Top achievements
Rank 1
answered on 07 Jun 2010, 02:56 PM
Thanks Daniel. This works.
0
Lubna Ansari
Top achievements
Rank 1
answered on 07 Jun 2010, 03:26 PM
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.

0
Daniel
Telerik team
answered on 09 Jun 2010, 09:48 PM
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.
0
Lubna Ansari
Top achievements
Rank 1
answered on 10 Jun 2010, 09:28 AM
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.
0
Accepted
Daniel
Telerik team
answered on 10 Jun 2010, 09:53 PM
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.
0
Lubna Ansari
Top achievements
Rank 1
answered on 11 Jun 2010, 10:09 AM
Hi Daniel,

The link solved the problem.

Regrads,
Lubna.
0
Nguyen Huu
Top achievements
Rank 1
answered on 26 Jun 2019, 04:11 AM

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?

0
Peter Milchev
Telerik team
answered on 28 Jun 2019, 01:47 PM
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.
Tags
Grid
Asked by
Lubna Ansari
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Lubna Ansari
Top achievements
Rank 1
Nguyen Huu
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or