Skip to content

Commit 2c79af0

Browse files
committed
support callback for rowTemplate
1 parent 1b8ee47 commit 2c79af0

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

app/sprinkles/core/assets/userfrosting/js/uf-table.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
addParams : {},
102102
filterAllField : '_all',
103103
useLoadingTransition : true,
104-
rowTemplateSelector : null,
104+
rowTemplate : null,
105105
tablesorter : {
106106
debug: false,
107107
theme : 'bootstrap',
@@ -291,6 +291,18 @@
291291
}
292292
}
293293

294+
// Locate and compile row template
295+
this.rowTemplate = Handlebars.compile('<tr>');
296+
// If rowTemplateSelector is set, then find the DOM element that it references, which contains the template
297+
if (this.settings.rowTemplate) {
298+
var rowTemplate = this.settings.rowTemplate;
299+
if (typeof rowTemplate === 'string') {
300+
this.rowTemplate = Handlebars.compile($(this.settings.rowTemplate).html());
301+
} else {
302+
this.rowTemplate = rowTemplate;
303+
}
304+
}
305+
294306
// Link CSV download button
295307
this.settings.downloadButton.on('click', this.settings.onDownload);
296308

@@ -421,12 +433,6 @@
421433
if (data) {
422434
var size = data.rows.length;
423435

424-
var rowTemplate = Handlebars.compile('<tr>');
425-
// If rowTemplateSelector is set, then find the DOM element that it references, which contains the template
426-
if (this.settings.rowTemplateSelector) {
427-
rowTemplate = Handlebars.compile($(this.settings.rowTemplateSelector).html());
428-
}
429-
430436
// Render table rows and cells via Handlebars
431437
for (var row = 0; row < size; row++) {
432438
var cellData = {
@@ -435,7 +441,7 @@
435441
site : site
436442
};
437443

438-
rows += rowTemplate(cellData);
444+
rows += this.rowTemplate(cellData);
439445

440446
for (var col = 0; col < this.columnTemplates.length; col++) {
441447
rows += this.columnTemplates[col](cellData);

0 commit comments

Comments
 (0)