Created
August 9, 2011 21:07
-
-
Save mikecleach/1135199 to your computer and use it in GitHub Desktop.
YUI3 augmenting datatable plugin to pull schema from received data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function DSJSInData(config) { | |
} | |
DSJSInData.NAME = "dsjsInData"; | |
DSJSInData.NS = "schema"; | |
Y.extend(DSJSInData, Y.Plugin.Base, { | |
initializer: function(config) { | |
this.doBefore("_defDataFn", this._beforeBeforeDefDataFn); | |
//Y.DSJSInData.superclass.initializer.apply(this, arguments); | |
this.doBefore("_defDataFn", this._beforeDefDataFn); | |
}, | |
_beforeBeforeDefDataFn: function(e) { | |
var data = e.data ? (e.data.responseText ? e.data.responseText : e.data) : e.data; | |
if(data.resultFields != null) { | |
var theFields = data.resultFields.split("-"); | |
var theSchema = { | |
resultListLocator: "query.results.Result", | |
resultFields: theFields | |
}; | |
this.set("schema", theSchema); | |
} | |
else { //bad data received, replace data with error information | |
e.data = "Data Error"; | |
} | |
} | |
}); | |
//Must be augment! The other option is extend, but extends calls superclass constructors first. | |
//This is a problem because what we need to do is hook a function in to run BEFORE the original JSON | |
//schema's initializer is run. Augmenting with the third parameter equal to true causes the new schema's | |
//properties to overwrite the old schema's properties with the same name. The only caveat to this is | |
//that you must repeat the original plugin's initializer code after our new code, since the overwriting means | |
//that the original initializer will not run. | |
Y.augment(Y.Plugin.DataSourceJSONSchema, DSJSInData, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment