Added loaded callback and support for column classes.

d6
Frode Petterson 2014-10-20 16:52:44 +02:00
parent 36ed607f9e
commit 062a8921e2
2 changed files with 17 additions and 3 deletions

View File

@ -30,8 +30,10 @@ var H5PDataView = (function ($) {
* Make it possible to filter/search in the given column. * Make it possible to filter/search in the given column.
* e.g. [null, true, null, null] will make it possible to do a text * e.g. [null, true, null, null] will make it possible to do a text
* search in column 2. * search in column 2.
* @param {Function} loaded
* Callback for when data has been loaded.
*/ */
function H5PDataView(container, source, headers, l10n, classes, filters) { function H5PDataView(container, source, headers, l10n, classes, filters, loaded) {
var self = this; var self = this;
self.$container = $(container).addClass('h5p-data-view').html(''); self.$container = $(container).addClass('h5p-data-view').html('');
@ -41,6 +43,7 @@ var H5PDataView = (function ($) {
self.l10n = l10n; self.l10n = l10n;
self.classes = (classes === undefined ? {} : classes); self.classes = (classes === undefined ? {} : classes);
self.filters = (filters === undefined ? [] : filters); self.filters = (filters === undefined ? [] : filters);
self.loaded = loaded;
self.limit = 20; self.limit = 20;
self.offset = 0; self.offset = 0;
@ -70,11 +73,13 @@ var H5PDataView = (function ($) {
} }
// Add filters // Add filters
var filtering;
for (var i = 0; i < self.filterOn.length; i++) { for (var i = 0; i < self.filterOn.length; i++) {
if (self.filterOn[i] === undefined) { if (self.filterOn[i] === undefined) {
continue; continue;
} }
filtering = true;
url += '&filters[' + i + ']=' + encodeURIComponent(self.filterOn[i]); url += '&filters[' + i + ']=' + encodeURIComponent(self.filterOn[i]);
} }
@ -88,7 +93,7 @@ var H5PDataView = (function ($) {
self.setMessage($('<p/>', {text: self.l10n.ajaxFailed})); self.setMessage($('<p/>', {text: self.l10n.ajaxFailed}));
}).done(function (data) { }).done(function (data) {
if (!data.rows.length) { if (!data.rows.length) {
self.setMessage($('<p/>', {text: self.l10n.noData})); self.setMessage($('<p/>', {text: filtering ? self.l10n.noData : self.l10n.empty}));
} }
else { else {
// Update table data // Update table data
@ -97,6 +102,10 @@ var H5PDataView = (function ($) {
// Update pagination widget // Update pagination widget
self.updatePagination(data.num); self.updatePagination(data.num);
if (self.loaded !== undefined) {
self.loaded();
}
}); });
}; };

View File

@ -172,7 +172,12 @@ var H5PUtils = H5PUtils || {};
options.text = col; options.text = col;
} }
else { else {
if (col.text !== undefined) {
options.text = col.text; options.text = col.text;
}
if (col.class !== undefined) {
options.class = col.class;
}
if (sortByCol !== undefined && col.sortable === true) { if (sortByCol !== undefined && col.sortable === true) {
// Make sortable // Make sortable