From f6b9c4c79621e9634b36e792a9ccd9e8f672ced7 Mon Sep 17 00:00:00 2001 From: AixaMartinez Date: Wed, 22 Apr 2015 16:43:42 +0100 Subject: [PATCH] Update jquery.dynatable.js 1. I changed single quotes to double quotes. This wasn't getting an error but loads of warnings. 2. I've got a dynatable with several filters. Each filter has been populated with certain values + empty string to allow users to select all or just some of them. If I select a value in the first filter and leave the other filters blank it works fine. But if I leave the first filter empty and I select a value in any of the others filters the table doesn't finish loading because there is an error. Where? in the line 1553 (Cannot convert undefined or null to object) it tries to delete from the urlOptions an undefined object. You need to check if label is undefined before trying to delete it, line 1553: if (typeof urlOptions[label] === "undefined"){ urlOptions[label] = {}; } I added this condition in line 1564 because I think It could happen too. What do you think? :) Looking forward to hearing from you soon. Regards, Aixa --- jquery.dynatable.js | 452 ++++++++++++++++++++------------------------ 1 file changed, 201 insertions(+), 251 deletions(-) diff --git a/jquery.dynatable.js b/jquery.dynatable.js index 9285e1e..0aae57f 100644 --- a/jquery.dynatable.js +++ b/jquery.dynatable.js @@ -53,56 +53,46 @@ perPageSelect: true }, table: { - defaultColumnIdStyle: 'camelCase', + defaultColumnIdStyle: "camelCase", columns: null, - headRowSelector: 'thead tr', // or e.g. tr:first-child - bodyRowSelector: 'tbody tr', - headRowClass: null, - copyHeaderAlignment: true, - copyHeaderClass: false + headRowSelector: "thead tr", // or e.g. tr:first-child + bodyRowSelector: "tbody tr", + headRowClass: null }, inputs: { queries: null, sorts: null, - multisort: ['ctrlKey', 'shiftKey', 'metaKey'], + multisort: ["ctrlKey", "shiftKey", "metaKey"], page: null, - queryEvent: 'blur change', + queryEvent: "blur change", recordCountTarget: null, - recordCountPlacement: 'after', + recordCountPlacement: "after", paginationLinkTarget: null, - paginationLinkPlacement: 'after', - paginationClass: 'dynatable-pagination-links', - paginationLinkClass: 'dynatable-page-link', - paginationPrevClass: 'dynatable-page-prev', - paginationNextClass: 'dynatable-page-next', - paginationActiveClass: 'dynatable-active-page', - paginationDisabledClass: 'dynatable-disabled-page', - paginationPrev: 'Previous', - paginationNext: 'Next', + paginationLinkPlacement: "after", + paginationClass: "dynatable-pagination-links", + paginationLinkClass: "dynatable-page-link", + paginationPrevClass: "dynatable-page-prev", + paginationNextClass: "dynatable-page-next", + paginationActiveClass: "dynatable-active-page", + paginationDisabledClass: "dynatable-disabled-page", + paginationPrev: "Previous", + paginationNext: "Next", paginationGap: [1,2,2,1], searchTarget: null, - searchPlacement: 'before', - searchText: 'Search: ', + searchPlacement: "before", perPageTarget: null, - perPagePlacement: 'before', - perPageText: 'Show: ', - pageText: 'Pages: ', - recordCountPageBoundTemplate: '{pageLowerBound} to {pageUpperBound} of', - recordCountPageUnboundedTemplate: '{recordsShown} of', - recordCountTotalTemplate: '{recordsQueryCount} {collectionName}', - recordCountFilteredTemplate: ' (filtered from {recordsTotal} total records)', - recordCountText: 'Showing', - recordCountTextTemplate: '{text} {pageTemplate} {totalTemplate} {filteredTemplate}', - recordCountTemplate: '{textTemplate}', - processingText: 'Processing...' + perPagePlacement: "before", + perPageText: "Show: ", + recordCountText: "Showing ", + processingText: "Processing..." }, dataset: { ajax: false, ajaxUrl: null, ajaxCache: null, ajaxOnLoad: false, - ajaxMethod: 'GET', - ajaxDataType: 'json', + ajaxMethod: "GET", + ajaxDataType: "json", totalRecordCount: null, queries: {}, queryRecordCount: null, @@ -110,7 +100,7 @@ perPageDefault: 10, perPageOptions: [10,20,50,100], sorts: {}, - sortsKeys: [], + sortsKeys: null, sortTypes: {}, records: null }, @@ -124,16 +114,16 @@ _attributeReader: defaultAttributeReader }, params: { - dynatable: 'dynatable', - queries: 'queries', - sorts: 'sorts', - page: 'page', - perPage: 'perPage', - offset: 'offset', - records: 'records', + dynatable: "dynatable", + queries: "queries", + sorts: "sorts", + page: "page", + perPage: "perPage", + offset: "offset", + records: "records", record: null, - queryRecordCount: 'queryRecordCount', - totalRecordCount: 'totalRecordCount' + queryRecordCount: "queryRecordCount", + totalRecordCount: "totalRecordCount" } }; @@ -187,7 +177,7 @@ }; build = function() { - this.$element.trigger('dynatable:preinit', this); + this.$element.trigger("dynatable:preinit", this); for (model in modelPrototypes) { if (modelPrototypes.hasOwnProperty(model)) { @@ -198,9 +188,9 @@ } } - this.$element.trigger('dynatable:init', this); + this.$element.trigger("dynatable:init", this); - if (!this.settings.dataset.ajax || (this.settings.dataset.ajax && this.settings.dataset.ajaxOnLoad) || this.settings.features.paginate || (this.settings.features.sort && !$.isEmptyObject(this.settings.dataset.sorts))) { + if (!this.settings.dataset.ajax || (this.settings.dataset.ajax && this.settings.dataset.ajaxOnLoad) || this.settings.features.paginate) { this.process(); } }; @@ -208,7 +198,7 @@ processAll = function(skipPushState) { var data = {}; - this.$element.trigger('dynatable:beforeProcess', data); + this.$element.trigger("dynatable:beforeProcess", data); if (!$.isEmptyObject(this.settings.dataset.queries)) { data[this.settings.params.queries] = this.settings.dataset.queries; } // TODO: Wrap this in a try/rescue block to hide the processing indicator and indicate something went wrong if error @@ -233,10 +223,9 @@ dataType: _this.settings.dataset.ajaxDataType, data: data, error: function(xhr, error) { - _this.$element.trigger('dynatable:ajax:error', {xhr: xhr, error : error}); }, success: function(response) { - _this.$element.trigger('dynatable:ajax:success', response); + _this.$element.trigger("dynatable:ajax:success", response); // Merge ajax results and meta-data into dynatables cached data _this.records.updateFromJson(response); // update table with new records @@ -280,47 +269,41 @@ this.state.push(data); } } - - this.$element.addClass('dynatable-loaded'); - this.$element.trigger('dynatable:afterProcess', data); + this.$element.trigger("dynatable:afterProcess", data); }; function defaultRowWriter(rowIndex, record, columns, cellWriter) { - var tr = ''; + var tr = ""; // grab the record's attribute for each column for (var i = 0, len = columns.length; i < len; i++) { tr += cellWriter(columns[i], record); } - return '' + tr + ''; + return "" + tr + ""; }; function defaultCellWriter(column, record) { var html = column.attributeWriter(record), - td = '