W3Data Controllers
What is a Controller?
A controller is a function you write to control your data.
With a self written controller, you can modify data anyway you want.
You can:
- Convert to upper case
- Convert currencies
- Calculate and Summarize
- Round values
- Substitute values
- Change colors according to values
- Anything else you are able to program
Adding a Controller
Adding a controller before displaying data, makes it possible to modify the data before they are displayed.
Example
// Added a controller to modify data before display
myController();
w3DisplayData("id01", myObject);
Controller Examples
Convert to Upper Case
function myController() {
var i, x;
var myArray = myObject["cd"];
for (i = 0; i < myArray.length; i++) {
myArray[i]["CustomerName"] =
myArray[i]["CustomerName"].toUpperCase();
}
}
Try It Yourself »
Summarize Price
function myController() {
var i;
var x;
var total = 0;
var myArray =
myObject["cd"];
for (i = 0; i < myArray.length; i++) {
total += Number(myArray[i]["price"]);
}
myObject["total"] = total.toFixed(2);
}
Try It Yourself »