Rating/AverageRating:
Unix timestamp:
A data table example
// enter global scripts here
({
"external" : null,
"xblBindingAttached": function() {
var oControl = this.boundElement; // points to extension control
var boundNodes = oControl.bind.defaultBinding.getBoundNodes()[0]; //defaultBinding.getBoundNodes()[0]
var instance; //holds the instance the boundNodes is part of
var instances = oControl.bind.model.instances.length;
for (var i = 0; i < instances; i++) {
instance = oControl.bind.model.instances[i];
if (instance.document == boundNodes.ownerDocument) {
break;
}
}
//
var myCustomFormatter = function(elCell, oRecord, oColumn, oData) {
var s = XForms.UNIX_DATE_FUNCTION.evaluate(oRecord.getData("LastReviewDate")); // See how easy it is to call XForms function
elCell.innerHTML = s;
}
YAHOO.hblink.w3cschema = function(inputValue, currentValue, editorInstance) {
return inputValue;
}
// Add the custom formatter to the shortcuts
YAHOO.widget.DataTable.Formatter["unixdate"] = myCustomFormatter;
var myColumnDefs = [
{key:"Title", label:"Name", sortable:true, formatter:this.formatUrl},
{key:"Phone"},
{key:"City"},
{key:"AverageRating", label:"Rating",
editor: new YAHOO.widget.TextboxCellEditor({
// validator:YAHOO.widget.DataTable.validateNumber,
validator: YAHOO.hblink.w3cschema, validator:YAHOO.widget.DataTable.validateNumber,
asyncSubmitter: YAHOO.hblink.asyncSubmitter
}),
sortable:true},
{key:"LastReviewDate", label:"Last Review Date",formatter:"unixdate"}
];
this.myDataSource = new YAHOO.util.DataSource(instance.document);
this.myDataSource.doBeforeCallback = function (oRequest, oFullResponse, oParsedResponse, oCallback) {
return oParsedResponse;
}
this.myDataSource.parseXMLData = YAHOO.hblink.parseXML;
this.myDataSource.bind = oControl.bind;
this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
this.myDataSource.responseSchema = {
resultNode: "Result",
fields: ["Title","Phone","City",{key:"AverageRating",xpath:"Rating/AverageRating"},
"ClickUrl",{key:"LastReviewDate",xpath:"Rating/LastReviewDate"}]
};
this.myDataSource.connMethodPost = false;
var htmlControl = document.getElementById("localxml");
this.myDataTable = new YAHOO.widget.DataTable(htmlControl, myColumnDefs, this.myDataSource,{initialLoad:false});
this.myDataTable.subscribe("cellClickEvent", this.myDataTable.onEventShowCellEditor);
new EventListener(document.documentElement, "xforms-ready" , "default" ,
hitch(this.myDataTable,function(){
this.getDataSource().bind.model.datatables.push(this);
this.getDataSource().sendRequest(
'',
{
success:this.onDataReturnInitializeTable,
scope:this
}
);
}));
},
xblEnteredDocument: function() {
},
xblLeftDocument: function() {
}
})