diff --git a/package.json b/package.json index 075cb62..1a89123 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "print-js", "homepage": "http://printjs.crabbly.com", "description": "A tiny javascript library to help printing from the web.", - "version": "1.0.47", + "version": "1.0.48", "main": "dist/print.js", "repository": "https://github.com/crabbly/Print.js", "license": "MIT", diff --git a/src/js/json.js b/src/js/json.js index 2950beb..dae1ceb 100644 --- a/src/js/json.js +++ b/src/js/json.js @@ -11,13 +11,24 @@ export default { throw new Error('Invalid javascript data object (JSON).') } - // Check if the repeatTableHeader is boolean + // Validate repeatTableHeader if (typeof params.repeatTableHeader !== 'boolean') { throw new Error('Invalid value for repeatTableHeader attribute (JSON).') } - // Check if properties were provided - if (!params.properties || !Array.isArray(params.properties)) throw new Error('Invalid properties array for your JSON data.') + // Validate properties + if (!params.properties || !Array.isArray(params.properties)) { + throw new Error('Invalid properties array for your JSON data.') + } + + // We will format the property objects to keep the JSON api compatible with older releases + params.properties = params.properties.map(property => { + return { + field: typeof property === 'object' ? property.field : property, + displayName: typeof property === 'object' ? property.displayName : property, + columnSize: typeof property === 'object' && property.columnSize + ';' ? property.columnSize : 100 / params.properties.length + '%;' + } + }) // Variable to hold the html string let htmlData = '' @@ -54,7 +65,7 @@ function jsonToHTML (params) { // Add the table header columns for (let a = 0; a < properties.length; a++) { - htmlData += '