使用PrintDocument 方法打印表格,如何设置让打印出来的表格有网格线?代码如下:
function printDocument(ids, title) {
var thistitle = title ? title : "tz";
var doc = new wijmo.PrintDocument({title: thistitle + new Date().Format('yyyy-MM-dd')});
if (!ids)
throw new Error('请传递flexid');
var flex = getFlexGrid(ids);
var tbl = renderTable(flex);
doc.append(tbl);
doc.print();
}
function renderTable(flex) {
// start table
var tbl = '<table>';
// headers
if (flex.headersVisibility & wijmo.grid.HeadersVisibility.Column) {
tbl += '<thead>';
for (var r = 0; r < flex.columnHeaders.rows.length; r++) {
tbl += renderRow(flex.columnHeaders, r);
}
tbl += '</thead>';
}
// body
tbl += '<tbody>';
for (var r = 0; r < flex.rows.length; r++) {
tbl += renderRow(flex.cells, r);
}
tbl += '</tbody>';
// done
tbl += '</table>';
return tbl;
}
function renderRow(panel, r) {
var tr = '',
row = panel.rows[r];
if (row.renderSize > 0) {
tr += '<tr>';
for (var c = 0; c < panel.columns.length; c++) {
var col = panel.columns[c];
if (col.renderSize > 0) {
// get cell style, content
var style = 'width:' + col.renderSize + 'px;' +
'text-align:' + col.getAlignment() + ';' +
'padding-right: 6px';
var content = panel.getCellData(r, c, true);
if (!row.isContentHtml && !col.isContentHtml) {
content = wijmo.escapeHtml(content);
}
// add cell to row
if (panel.cellType == wijmo.grid.CellType.ColumnHeader) {
tr += '<th style="' + style + '">' + content + '</th>';
} else {
// rt.Style.GridLines.All = LineDef.Default
// show boolean values as checkboxes
var raw = panel.getCellData(r, c, false);
if (raw === true) {
content = '☑';
} else if (raw === false) {
content = '☐';
}
tr += '<td style="' + style + '">' + content + '</td>';
}
}
}
tr += '</tr>';
}
return tr;
}
|