-
Notifications
You must be signed in to change notification settings - Fork 361
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,23 @@ | |
sortTypes: {}, | ||
records: null | ||
}, | ||
ajax: { | ||
ajaxComplete: 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 (obj.skipPushState && obj.state.initOnLoad()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably keep the way we reference the |
||
obj.state.push(data); | ||
} | ||
}, | ||
|
||
ajaxDone: function() { | ||
obj.processingIndicator.hide(); | ||
} | ||
}, | ||
writers: { | ||
_rowWriter: defaultRowWriter, | ||
_cellWriter: defaultCellWriter, | ||
|
@@ -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; } | ||
|
@@ -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) { | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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
andcomplete
instead ofajaxComplete
andajaxDone
just to keep naming consistent and reduce redundancy (since they're located in theajax
object, settingajax.success
andajax.complete
is a bit cleaner thanajax.ajaxComplete
, etc.