Good morning,
I'm trying to print all the selected rows in a RadGrid together with every nested row. My table contains master table rows and each row, when expanded, contains 4 extra rows. I'm using the code example below for printing but it only prints the selected rows (if the master table row is not expanded and every nested row not selected, it will just print the master table row).
function
PrintGrid() {
var
sh =
'<%= ClientScript.GetWebResourceUrl(RadGrid1.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",RadGrid1.Skin)) %>'
;
var
styleStr =
"<html><head><link href = '"
+ sh +
"' rel='stylesheet' type='text/css'></link></head>"
;
var
MasterTable = $find(
'<%= RadGrid1.ClientID %>'
).get_masterTableView();
var
selectedRows = MasterTable.get_selectedItems();
var
htmlcontent =
"<table>"
;
for
(
var
i = 0; i < selectedRows.length; i++) {
var
row = selectedRows[i];
htmlcontent = htmlcontent +
"<tr>"
+ row.get_element().innerHTML +
"</tr>"
;
if (row.get_nestedViews().length > 0) {
var nestedSelectedRows = row.get_nestedViews()[0].get_selectedItems();
for (var j = 0; j < nestedSelectedRows.length; j++) {
var nestedRow = nestedSelectedRows[j];
htmlcontent = htmlcontent + "<tr>" + nestedRow.get_element().innerHTML + "</tr>";
}
}
}
htmlcontent = styleStr +
"<body><div class='RadGrid RadGrid_Metro'>"
+ htmlcontent +
"</table></div></body></html>"
;
var
previewWnd = window.open(
'about:blank'
,
''
,
''
,
false
);
previewWnd.document.open();
previewWnd.document.write(htmlcontent);
previewWnd.document.close();
previewWnd.print();
}
I'm currently lost and don't know how to take this further. Should I expand all the nested rows and select them on print button click, print the document, and then collapse them again or is there a better/faster way to do this?