Skip to content

Commit

Permalink
Merge pull request wenzhixin#3540 from riggzh/patch-1
Browse files Browse the repository at this point in the history
Complex Table can't print
  • Loading branch information
wenzhixin authored Jan 15, 2018
2 parents 0d14767 + d49413f commit b381fc5
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/extensions/print/bootstrap-table-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,38 @@
}
}

function buildTable(data,columns) {
var out = "<table><thead><tr>";
for(var h = 0; h < columns.length; h++) {
if(!columns[h].printIgnore) {
out += ("<th>"+columns[h].title+"</th>");
function buildTable(data, columnsArray) {
var html = ['<table><thead>'];
for (var k = 0; k < columnsArray.length; k++) {
var columns = columnsArray[k];
html.push('<tr>');
for (var h = 0; h < columns.length; h++) {
if (!columns[h].printIgnore) {
html.push(
'<th',
sprintf(' rowspan="%s"', columns[h].rowspan),
sprintf(' colspan="%s"', columns[h].colspan),
sprintf('>%s</th>', columns[h].title)
);
}
}
html.push('</tr>');
}
out += "</tr></thead><tbody>";
for(var i = 0; i < data.length; i++) {
out += "<tr>";
for(var j = 0; j < columns.length; j++) {
if(!columns[j].printIgnore) {
out += ("<td>"+ formatValue(data[i], i, columns[j])+"</td>");
html.push('</thead><tbody>');
for (var i = 0; i < data.length; i++) {
html.push('<tr>');
for(var l = 0; l < columnsArray.length; l++) {
var columns = columnsArray[l];
for(var j = 0; j < columns.length; j++) {
if (!columns[j].printIgnore && columns[j].field) {
html.push('<td>', formatValue(data[i], i, columns[j]), '</td>');
}
}
}
out += "</tr>";
html.push('</tr>');
}
out += "</tbody></table>";
return out;
html.push('</tbody></table>');
return html.join('');
}
function sortRows(data,colName,sortOrder) {
if(!colName){
Expand Down Expand Up @@ -122,7 +135,7 @@
var doPrint = function (data) {
data=filterRows(data,getColumnFilters(that.options.columns));
data=sortRows(data,that.options.printSortColumn,that.options.printSortOrder);
var table=buildTable(data,that.options.columns[0]);
var table=buildTable(data,that.options.columns);
var newWin = window.open("");
newWin.document.write(that.options.printPageBuilder.call(this, table));
newWin.print();
Expand Down

0 comments on commit b381fc5

Please sign in to comment.