原創|使用教程|編輯:龔雪|2020-08-05 10:11:37.183|閱讀 352 次
概述:Kendo UI for jQuery是創建現代Web應用程序的最完整UI庫,即使Grid的內容可能不是頁面上的唯一內容,Grid也提供忽略頁面其余部分并僅打印其內容的選項。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Kendo UI for jQuery R2 2020 SP1試用版下載
Kendo UI目前最新提供Kendo UI for jQuery、Kendo UI for Angular、Kendo UI Support for React和Kendo UI Support for Vue四個控件。Kendo UI for jQuery是創建現代Web應用程序的最完整UI庫。
即使Grid的內容可能不是頁面上的唯一內容,Grid也提供忽略頁面其余部分并僅打印其內容的選項。
要僅從頁面上打印Grid,請使用以下兩種方法:
打印現有網頁
若要僅將Grid作為現有網頁的一部分進行打印,請使用打印樣式表隱藏頁面中不需要的部分,確切的CSS打印取決于現有頁面內容。
打印新網頁
下面的示例演示如何檢索Grid的HTML,如何將其注入到新的瀏覽器窗口中以及打印新頁面。 此方法還解決了以下重要問題:
<div id="grid"></div> <script type="text/x-kendo-template" id="toolbar-template"> <button type="button" class="k-button" id="printGrid">Print Grid</button> </script>
function printGrid() { var gridElement = $('#grid'), printableContent = '', win = window.open('', '', 'width=800, height=500, resizable=1, scrollbars=1'), doc = win.document.open(); var htmlStart = '<!DOCTYPE html>' + '<html>' + '<head>' + '<meta charset="utf-8" />' + '<title>Kendo UI Grid</title>' + '<link + kendo.version + '/styles/kendo.common.min.css" rel="stylesheet" /> ' + '<style>' + 'html { font: 11pt sans-serif; }' + '.k-grid { border-top-width: 0; }' + '.k-grid, .k-grid-content { height: auto !important; }' + '.k-grid-content { overflow: visible !important; }' + 'div.k-grid table { table-layout: auto; width: 100% !important; }' + '.k-grid .k-grid-header th { border-top: 1px solid; }' + '.k-grouping-header, .k-grid-toolbar, .k-grid-pager > .k-link { display: none; }' + // '.k-grid-pager { display: none; }' + // optional: hide the whole pager '</style>' + '</head>' + '<body>'; var htmlEnd = '</body>' + '</html>'; var gridHeader = gridElement.children('.k-grid-header'); if (gridHeader[0]) { var thead = gridHeader.find('thead').clone().addClass('k-grid-header'); printableContent = gridElement .clone() .children('.k-grid-header').remove() .end() .children('.k-grid-content') .find('table') .first() .children('tbody').before(thead) .end() .end() .end() .end()[0].outerHTML; } else { printableContent = gridElement.clone()[0].outerHTML; } doc.write(htmlStart + printableContent + htmlEnd); doc.close(); win.print(); } $(function () { var grid = $('#grid').kendoGrid({ dataSource: { type: 'odata', transport: { read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products" }, pageSize: 20, serverPaging: true, serverSorting: true, serverFiltering: true }, toolbar: kendo.template($('#toolbar-template').html()), height: 400, pageable: true, columns: [ { field: 'ProductID', title: 'Product ID', width: 100 }, { field: 'ProductName', title: 'Product Name' }, { field: 'UnitPrice', title: 'Unit Price', width: 100 }, { field: 'QuantityPerUnit', title: 'Quantity Per Unit' } ] }); $('#printGrid').click(function () { printGrid(); }); });
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網