voilab-pdf-table
Advanced tools
Comparing version 0.1.5 to 0.2.0
{ | ||
"name": "voilab-pdf-table", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "PdfKit wrapper that helps to draw informations in simple tables.", | ||
@@ -5,0 +5,0 @@ "main": "voilab-table.js", |
@@ -50,6 +50,33 @@ /*jslint node: true, unparam: true, nomen: true */ | ||
.onBodyAdd(this.setWidth.bind(this)) | ||
.onColumnWidthChanged(this.reinitWidth.bind(this)); | ||
.onColumnAdded(this.onColumnAdded.bind(this)) | ||
.onColumnPropertyChanged(this.onColumnPropertyChanged.bind(this)); | ||
}, | ||
/** | ||
* Reinit width after a column is added | ||
* | ||
* @param {PdfTable} | ||
* @return {PdfTableFitColumn} | ||
*/ | ||
onColumnAdded: function (table) { | ||
return this.reinitWidth(table); | ||
}, | ||
/** | ||
* Reinit width after width or hidden property changed | ||
* | ||
* @param {PdfTable} table | ||
* @param {Object} column | ||
* @param {String} prop | ||
* @return {PdfTableFitColumn} | ||
*/ | ||
onColumnPropertyChanged: function (table, column, prop) { | ||
// manage width changes and show/hide changes | ||
if (prop !== 'width' && prop !== 'hidden') { | ||
return this; | ||
} | ||
return this.reinitWidth(table); | ||
}, | ||
/** | ||
* Reset width, so calculation can be re-executed | ||
@@ -56,0 +83,0 @@ * |
@@ -45,3 +45,3 @@ Voilab Pdf Table | ||
header: 'Quantity', | ||
width: 40 | ||
width: 50 | ||
}, | ||
@@ -88,4 +88,27 @@ { | ||
### Page breaks | ||
You can customize how page breaks are done during table process like this: | ||
```js | ||
table.setNewPageFn(function (table, row) { | ||
// do something like | ||
table.pdf.addPage(); | ||
}); | ||
``` | ||
## Changelogs | ||
### 0.2.0 | ||
+ added event `onColumnPropertyChanged` | ||
+ added event `onColumnAdded` | ||
+ removed `onColumnWidthChanged`. Use `onColumnPropertyChanged` instead. | ||
Deprecated mention will be definitively removed in next release | ||
+ Issue #1 fix | ||
### 0.1.5 | ||
First shot | ||
## Licence | ||
This code is released under the MIT License (MIT) |
@@ -108,3 +108,3 @@ /*jslint node: true, unparam: true, nomen: true */ | ||
if (self.newPageFn) { | ||
self.newPageFn(self); | ||
self.newPageFn(self, row); | ||
self.emitter.emit('page-added', self); | ||
@@ -377,5 +377,7 @@ } | ||
* </ul> | ||
* @deprecated | ||
* @return {PdfTable} | ||
*/ | ||
onColumnWidthChanged: function (fn) { | ||
console.log("this event is deprecated, use onColumnPropertyChanged instead"); | ||
this.emitter.on('column-width-changed', fn); | ||
@@ -386,2 +388,30 @@ return this; | ||
/** | ||
* Add action after a column is added | ||
* <ul> | ||
* <li><i>PdfTable</i> <b>table</b> PdfTable behind the event</li> | ||
* <li><i>Object</i> <b>column</b> the added column</li> | ||
* </ul> | ||
* @return {PdfTable} | ||
*/ | ||
onColumnAdded: function (fn) { | ||
this.emitter.on('column-added', fn); | ||
return this; | ||
}, | ||
/** | ||
* Add action after a column's property is changed | ||
* <ul> | ||
* <li><i>PdfTable</i> <b>table</b> PdfTable behind the event</li> | ||
* <li><i>Object</i> <b>column</b> the column< that changed/li> | ||
* <li><i>string</i> <b>prop</b> the property that changed</li> | ||
* <li><i>mixed</i> <b>oldValue</b> the property value before change/li> | ||
* </ul> | ||
* @return {PdfTable} | ||
*/ | ||
onColumnPropertyChanged: function (fn) { | ||
this.emitter.on('column-property-changed', fn); | ||
return this; | ||
}, | ||
/** | ||
* Temporary hack to manage overriden addPage() for pdfkit | ||
@@ -461,3 +491,2 @@ * | ||
* bottom)</li> | ||
* <li><i>String</i> <b>border</b>: cell border (LTBR)</li> | ||
* <li><i>Boolean</i> <b>fill</b>: True to fill the cell with the | ||
@@ -493,3 +522,3 @@ * predefined color (with pdf.fillColor(color))</li> | ||
this.columns.push(lodash.assign(lodash.clone(this.columnsDefaults || {}), column)); | ||
this.setColumnWidth(column.id, column.width); | ||
this.emitter.emit('column-added', this, column); | ||
return this; | ||
@@ -691,7 +720,10 @@ }, | ||
setColumnParam: function (columnId, key, value, silent) { | ||
var column = this.getColumn(columnId); | ||
var column = this.getColumn(columnId), | ||
old_value; | ||
if (column) { | ||
old_value = column[key]; | ||
column[key] = value; | ||
if (!silent && key === 'width') { | ||
this.emitter.emit('column-width-changed', this, column); | ||
if (!silent) { | ||
this.emitter.emit('column-property-changed', this, column, key, old_value); | ||
} | ||
@@ -730,2 +762,6 @@ } | ||
this.emitter.emit('body-added', this, data); | ||
// Issue #1, restore x position after table is drawn | ||
self.pdf.x = self.pdf.page.margins.left; | ||
return this; | ||
@@ -732,0 +768,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31814
827
113