|
202 | 202 | /** |
203 | 203 | * Create a table from a set of data. |
204 | 204 | * @param {Object[]} dataSet As array of objects containing key-value pairs |
205 | | - * @param {Array} [headers] Omit or null to auto-generate headers at a performance cost |
| 205 | + * @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost |
206 | 206 | * @param {Object} [config.printHeaders] True to print column headers at the top of every page |
207 | 207 | * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value |
208 | 208 | * @param {Object} [config.autoStretch] True to force the table to fit the width of the page |
209 | 209 | */ |
210 | | - jsPDFAPI.table = function(dataSet, headers, config){ |
| 210 | + jsPDFAPI.table = function(data, headers, config){ |
211 | 211 |
|
212 | 212 | var models; |
213 | 213 |
|
|
223 | 223 | autoStretch = config.autoStretch || true; |
224 | 224 | } |
225 | 225 |
|
226 | | - if(!dataSet){ |
| 226 | + if(!data){ |
227 | 227 | throw 'No data for PDF table'; |
228 | 228 | } |
229 | 229 |
|
230 | | - if(dataSet.isStore){ |
231 | | - var isStore = true; |
232 | | - models = dataSet.data.items; |
233 | | - } else { |
234 | | - models = dataSet; |
235 | | - } |
236 | | - |
237 | 230 | // Set headers |
238 | 231 | if(headers === undefined || (headers === null)){ |
239 | 232 | // No headers defined so we derive from data |
240 | | - headers = this.getKeys(models[0]); |
| 233 | + headers = this.getKeys(data[0]); |
241 | 234 | } |
242 | 235 |
|
243 | 236 | if(config.autoSize){ |
|
250 | 243 |
|
251 | 244 | for (var i = 0, ln = headers.length; i < ln; i++) { |
252 | 245 | index = headers[i]; |
253 | | - columnMatrix[index] = models.map(function(rec){ |
| 246 | + columnMatrix[index] = data.map(function(rec){ |
254 | 247 | return rec[index]; |
255 | 248 | }); |
256 | 249 |
|
|
293 | 286 | // Construct the data rows |
294 | 287 | var model; |
295 | 288 |
|
296 | | - for (var i = 0, ln = models.length; i < ln; i++) { |
297 | | - model = models[i]; |
| 289 | + for (var i = 0, ln = data.length; i < ln; i++) { |
| 290 | + model = data[i]; |
298 | 291 |
|
299 | 292 | for (var j = 0, jln = headers.length; j < jln; j++) { |
300 | 293 | index = headers[j]; |
|
0 commit comments