Hallo, please help me. I could not reload right the DataSource of the DataTable component. The DataSource I get from mySQl. When I want to refresh my data (previously change some data into the base) using methods above or just by reloading the page (F5), nothig was happen. I have took into acount that when I click to the field for sorting: in one direction it show right result...in another - old list of data???...This is my code:
YAHOO.example.DynamicData = function() {
// Column definitions
var myColumnDefs = [ // sortable:true enables sorting
{key:"ID", label:"ID", sortable:true},
{key:"Date", label:"Date", sortable:true},
{key:"Time", label:"Time" /, formatter:"date"/ },
{key:"TotalCharge", label:"TotalCharge", sortable:true},
{key:"TotalEnergy", label:"TotalEnergy", sortable:true},
{key:"MaxPeak", label:"MaxPeak", sortable:true},
{key:"NumbOfStrokes", label:"NumbOfStrokes", sortable:true},
{key:"jpgID", label:"jpgID", sortable:true}
];
// Custom parser
var stringToDate = function(sData) {
var array = sData.split("-");
return new Date(array[1] + " " + array[0] + ", " + array[2]);
};
// DataSource instance
var myDataSource = new YAHOO.util.DataSource("json_proxy.php?");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
myDataSource.responseSchema = {
resultsList: "records",
fields: [
{key:"ID", parser:"number"},
{key:"Date"},
{key:"Time" /*parser:stringToDate*/ },
{key:"TotalCharge",parser:"number"},
{key:"TotalEnergy",parser:"number"},
{key:"MaxPeak",parser:"number"},
{key:"NumbOfStrokes",parser:"number"},
{key:"jpgID"}
],
metaFields: {
totalRecords: "totalRecords" // Access to value in the server response
}
};
// DataTable configuration
var myConfigs = {
initialRequest: "sort=ID&dir=asc&startIndex=0&results=25", // Initial request for first page of data
dynamicData: true, // Enables dynamic server-driven data
sortedBy : {key:"ID", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets UI initial sort arrow
paginator: new YAHOO.widget.Paginator({ rowsPerPage:25 }) // Enables pagination
};
// DataTable instance
var myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, myDataSource, myConfigs);
// Update totalRecords on the fly with value from server
myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}
return {
ds: myDataSource,
dt: myDataTable
};
}();