原創(chuàng)|使用教程|編輯:龔雪|2020-08-05 10:11:37.183|閱讀 352 次
概述:Kendo UI for jQuery是創(chuàng)建現(xiàn)代Web應(yīng)用程序的最完整UI庫(kù),即使Grid的內(nèi)容可能不是頁(yè)面上的唯一內(nèi)容,Grid也提供忽略頁(yè)面其余部分并僅打印其內(nèi)容的選項(xiàng)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
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四個(gè)控件。Kendo UI for jQuery是創(chuàng)建現(xiàn)代Web應(yīng)用程序的最完整UI庫(kù)。
即使Grid的內(nèi)容可能不是頁(yè)面上的唯一內(nèi)容,Grid也提供忽略頁(yè)面其余部分并僅打印其內(nèi)容的選項(xiàng)。
要僅從頁(yè)面上打印Grid,請(qǐng)使用以下兩種方法:
打印現(xiàn)有網(wǎng)頁(yè)
若要僅將Grid作為現(xiàn)有網(wǎng)頁(yè)的一部分進(jìn)行打印,請(qǐng)使用打印樣式表隱藏頁(yè)面中不需要的部分,確切的CSS打印取決于現(xiàn)有頁(yè)面內(nèi)容。
打印新網(wǎng)頁(yè)
下面的示例演示如何檢索Grid的HTML,如何將其注入到新的瀏覽器窗口中以及打印新頁(yè)面。 此方法還解決了以下重要問(wèn)題:
<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(); }); });
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)