Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ajaxComplete and ajaxDone customization #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions jquery.dynatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@
sortTypes: {},
records: null
},
ajax: {
ajaxComplete: function(response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just call these settings success and complete instead of ajaxComplete and ajaxDone just to keep naming consistent and reduce redundancy (since they're located in the ajax object, setting ajax.success and ajax.complete is a bit cleaner than ajax.ajaxComplete, etc.

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
this.dom.update();

if (obj.skipPushState && obj.state.initOnLoad()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably keep the way we reference the this object consistent within the function here; seems like we randomly switch from directly calling this to then start calling the equivalent obj. I'd do it one way or the other.

obj.state.push(data);
}
},

ajaxDone: function() {
obj.processingIndicator.hide();
}
},
writers: {
_rowWriter: defaultRowWriter,
_cellWriter: defaultCellWriter,
Expand Down Expand Up @@ -207,7 +224,6 @@

processAll = function(skipPushState) {
var data = {};

this.$element.trigger('dynatable:beforeProcess', data);

if (!$.isEmptyObject(this.settings.dataset.queries)) { data[this.settings.params.queries] = this.settings.dataset.queries; }
Expand All @@ -232,22 +248,9 @@
type: _this.settings.dataset.ajaxMethod,
dataType: _this.settings.dataset.ajaxDataType,
data: data,
error: function(xhr, error) {
},
success: function(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
_this.dom.update();

if (!skipPushState && _this.state.initOnLoad()) {
_this.state.push(data);
}
},
complete: function() {
_this.processingIndicator.hide();
}
error: function(xhr, error) { },
success: _this.settings.ajax.ajaxSuccess,
complete: _this.settings.ajax.ajaxDone
};
// Do not pass url to `ajax` options if blank
if (this.settings.dataset.ajaxUrl) {
Expand Down Expand Up @@ -592,6 +595,8 @@
// Create cache of original full recordset (unpaginated and unqueried)
settings.dataset.originalRecords = $.extend(true, [], settings.dataset.records);
};
this.ajaxSuccess = obj.settings.ajax.ajaxSuccess
this.ajaxDone = obj.settings.ajax.ajaxDone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure these two lines are needed, I'd leave them out.


// merge ajax response json with cached data including
// meta-data and records
Expand Down