Skip to content

Instantly share code, notes, and snippets.

@jgdovin
Created June 3, 2015 18:02
Show Gist options
  • Save jgdovin/eadd56e5395907808096 to your computer and use it in GitHub Desktop.
Save jgdovin/eadd56e5395907808096 to your computer and use it in GitHub Desktop.
(function ($) {
'use strict';
var hotPrint = function (instance) {
var _self = this;
_self.instance = instance;
this.printToHtml = function () {
var _grid = _self.instance;
var numRows = _self.instance.countRows();
var numCols = _self.instance.countCols();
var r, c;
var rows = [], cols = [], headers = [];
var cellNode;
var topRow = _self.instance.getDataAtRow(0);
_self.instance.destroyEditor();
for (r = 0; r < 35; r++) {
cols = [];
for (c = 0; c < numCols; c++) {
cellNode = _grid.getDataAtCell(r, c);
if(cellNode === 'NA') {
cellNode = '';
}
cols.push(cellNode);
}
rows.push('<td height="5" style="width: 200px; font-size: .5em">' + cols.join('</td><td height="5" style="width: 80px; font-size: .5em">') + '</td>');
}
console.log(rows);
var table = [
'<table class="table table-bordered">',
'<tbody>',
'<tr>' + rows.join('</tr>\n<tr style="height: 5px;">') + '</tr>',
'</tbody>',
'</table>'
].join('\n');
return table;
}
this.printToElement = function ($element) {
$($element).html(_self.printToHtml());
};
this.printToWindow = function (w) {
w.onload = function () {
setTimeout(function () {
_self.printToElement(w.document.body);
});
};
};
}
$.extend(true, window, {
HotTable: {
Plugins: {
Print: hotPrint
}
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment