|
805 | 805 | var body = []; |
806 | 806 | rowIndex = 0; |
807 | 807 |
|
808 | | - $hrows = $(this).find('thead').first().find(defaults.theadSelector); |
809 | | - $hrows.each(function () { |
810 | | - var h = []; |
| 808 | + var CollectPdfmakeData = function ($rows, colselector, length) { |
| 809 | + var rlength = 0; |
811 | 810 |
|
812 | | - ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, |
813 | | - function (cell, row, col) { |
814 | | - if (typeof cell !== 'undefined' && cell !== null) { |
| 811 | + $rows.each(function () { |
| 812 | + var r = []; |
| 813 | + |
| 814 | + ForEachVisibleCell(this, colselector, rowIndex, length, |
| 815 | + function (cell, row, col) { |
| 816 | + if (typeof cell !== 'undefined' && cell !== null) { |
815 | 817 |
|
816 | | - var colspan = parseInt(cell.getAttribute('colspan')); |
817 | | - var rowspan = parseInt(cell.getAttribute('rowspan')); |
| 818 | + var colspan = parseInt(cell.getAttribute('colspan')); |
| 819 | + var rowspan = parseInt(cell.getAttribute('rowspan')); |
818 | 820 |
|
819 | | - var cellValue = parseString(cell, row, col); |
| 821 | + var cellValue = parseString(cell, row, col) || " "; |
820 | 822 |
|
821 | | - if (colspan > 1 || rowspan > 1) { |
822 | | - colspan = colspan || 1; |
823 | | - rowspan = rowspan || 1; |
824 | | - h.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); |
| 823 | + if (colspan > 1 || rowspan > 1) { |
| 824 | + colspan = colspan || 1; |
| 825 | + rowspan = rowspan || 1; |
| 826 | + r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); |
| 827 | + } |
| 828 | + else |
| 829 | + r.push(cellValue); |
825 | 830 | } |
826 | 831 | else |
827 | | - h.push(cellValue); |
828 | | - } |
829 | | - }); |
| 832 | + r.push(" "); |
| 833 | + }); |
830 | 834 |
|
831 | | - if (h.length) |
832 | | - body.push(h); |
| 835 | + if (r.length) |
| 836 | + body.push(r); |
833 | 837 |
|
834 | | - for(var i = widths.length; i < h.length;i++) |
835 | | - widths.push("*"); |
| 838 | + if ( rlength < r.length ) |
| 839 | + rlength = r.length; |
836 | 840 |
|
837 | | - rowIndex++; |
838 | | - }); |
| 841 | + rowIndex++; |
| 842 | + }); |
| 843 | + |
| 844 | + return rlength; |
| 845 | + } |
| 846 | + |
| 847 | + $hrows = $(this).find('thead').first().find(defaults.theadSelector); |
| 848 | + |
| 849 | + var colcount = CollectPdfmakeData ($hrows, 'th,td', $hrows.length); |
| 850 | + |
| 851 | + for(var i = widths.length; i < colcount;i++) |
| 852 | + widths.push("*"); |
839 | 853 |
|
840 | 854 | $(this).find('tbody').each(function() { |
841 | 855 | $rows.push.apply ($rows, $(this).find(defaults.tbodySelector)); |
842 | 856 | }); |
843 | 857 | if (defaults.tfootSelector.length) |
844 | 858 | $rows.push.apply ($rows, $(this).find('tfoot').find(defaults.tfootSelector)); |
845 | 859 |
|
846 | | - $($rows).each(function () { |
847 | | - var r = []; |
848 | | - |
849 | | - ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, |
850 | | - function (cell, row, col) { |
851 | | - if (typeof cell !== 'undefined' && cell !== null) { |
852 | | - var colspan = parseInt(cell.getAttribute('colspan')); |
853 | | - var rowspan = parseInt(cell.getAttribute('rowspan')); |
854 | | - |
855 | | - var cellValue = parseString(cell, row, col) || " "; |
856 | | - |
857 | | - if (colspan > 1 || rowspan > 1) { |
858 | | - colspan = colspan || 1; |
859 | | - rowspan = rowspan || 1; |
860 | | - r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); |
861 | | - } |
862 | | - else |
863 | | - r.push(cellValue); |
864 | | - } |
865 | | - else |
866 | | - r.push(" "); |
867 | | - }); |
868 | | - |
869 | | - if (r.length) |
870 | | - body.push(r); |
871 | | - rowIndex++; |
872 | | - }); |
| 860 | + CollectPdfmakeData ($rows, 'th,td', $hrows.length + $rows.length); |
873 | 861 |
|
874 | 862 | var docDefinition = { content: [ { |
875 | 863 | table: { |
|
1323 | 1311 | }).find(selector); |
1324 | 1312 |
|
1325 | 1313 | var rowColspan = 0; |
1326 | | - var rowColIndex = 0; |
1327 | 1314 |
|
1328 | 1315 | $row.each(function (colIndex) { |
1329 | 1316 | if ($(this).data("tableexport-display") == 'always' || |
1330 | 1317 | ($(this).css('display') != 'none' && |
1331 | 1318 | $(this).css('visibility') != 'hidden' && |
1332 | 1319 | $(this).data("tableexport-display") != 'none')) { |
1333 | | - if (isColumnIgnored($row, colIndex) === false) { |
1334 | | - if (typeof (cellcallback) === "function") { |
1335 | | - var c, Colspan = 0; |
1336 | | - var r, Rowspan = 0; |
1337 | | - |
1338 | | - // handle rowspans from previous rows |
1339 | | - if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0) { |
1340 | | - for (c = 0; c <= colIndex; c++) { |
1341 | | - if (typeof rowspans[rowIndex][c] != 'undefined') { |
1342 | | - cellcallback(null, rowIndex, c); |
1343 | | - delete rowspans[rowIndex][c]; |
1344 | | - colIndex++; |
1345 | | - } |
| 1320 | + if (typeof (cellcallback) === "function") { |
| 1321 | + var c, Colspan = 1; |
| 1322 | + var r, Rowspan = 1; |
| 1323 | + |
| 1324 | + // handle rowspans from previous rows |
| 1325 | + if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0) { |
| 1326 | + var colCount = colIndex; |
| 1327 | + for (c = 0; c <= colCount; c++) { |
| 1328 | + if (typeof rowspans[rowIndex][c] != 'undefined') { |
| 1329 | + cellcallback(null, rowIndex, c); |
| 1330 | + delete rowspans[rowIndex][c]; |
| 1331 | + colCount++; |
1346 | 1332 | } |
1347 | 1333 | } |
1348 | | - rowColIndex = colIndex; |
| 1334 | + colIndex += rowspans[rowIndex].length; |
| 1335 | + } |
1349 | 1336 |
|
| 1337 | + if (isColumnIgnored($row, colIndex + rowColspan) === false) { |
1350 | 1338 | if ($(this).is("[colspan]")) { |
1351 | | - Colspan = parseInt($(this).attr('colspan')); |
| 1339 | + Colspan = parseInt($(this).attr('colspan')) || 1; |
| 1340 | + |
| 1341 | + for (c = 1; c < Colspan; c++) |
| 1342 | + if (isColumnIgnored($row, colIndex + c) === true) |
| 1343 | + Colspan--; |
| 1344 | + |
1352 | 1345 | rowColspan += Colspan > 0 ? Colspan - 1 : 0; |
1353 | 1346 | } |
1354 | 1347 |
|
1355 | 1348 | if ($(this).is("[rowspan]")) |
1356 | | - Rowspan = parseInt($(this).attr('rowspan')); |
| 1349 | + Rowspan = parseInt($(this).attr('rowspan')) || 1; |
1357 | 1350 |
|
1358 | 1351 | // output content of current cell |
1359 | 1352 | cellcallback(this, rowIndex, colIndex); |
1360 | 1353 |
|
1361 | 1354 | // handle colspan of current cell |
1362 | | - for (c = 0; c < Colspan - 1; c++) |
| 1355 | + for (c = 1; c < Colspan; c++) |
1363 | 1356 | cellcallback(null, rowIndex, colIndex + c); |
1364 | 1357 |
|
1365 | 1358 | // store rowspan for following rows |
1366 | | - if (Rowspan) { |
| 1359 | + if (Rowspan > 1) { |
1367 | 1360 | for (r = 1; r < Rowspan; r++) { |
1368 | 1361 | if (typeof rowspans[rowIndex + r] == 'undefined') |
1369 | 1362 | rowspans[rowIndex + r] = []; |
|
0 commit comments