Daten aus einer Datenbank
Ein TableGadget kann automatisch über eine Datenbank befüllt werden.
Dazu kann die Funktion fromDatabase verwendet werden.
Beispiel
Gadget_ou.cust.demo.tableGadget.filetype.field.exampleDB
// documents6 Syntax
const { TableGadget } = require("ou.sp.gadget.TableGadget");
const { Database, QueryBuilder } = require("ou.sp.Database");
const dbUser = util.getEnvironment("OUSP_DATABASE_USER");
const dbPassword = util.getEnvironment("OUSP_DATABASE_PASSWORD");
const db = new DBConnection("odbc", "ousp", dbUser, dbPassword);
const database = new Database(db);
const query = QueryBuilder.select(["recipient", "costcenter", "costcenterName"])
.from("costcenter")
.orderBy("recipient")
.orderBy("costcenter");
const gadget = TableGadget.fromDatabase(database, query);
gadget.options.id = "exampleDB";
gadget.options.showOptions = true;
gadget.options.showFooter = true;
gadget.options.showPagination = true;
gadget.options.pageSize = 10;
gadget.options.columns = {
recipient: {
label: "Rechnungskreis",
field: "recipient",
},
costcenter: {
label: "Id",
field: "costcenter",
},
costcenterName: {
label: "Kostenstelle",
field: "costcenterName",
},
};
if (db) {
db.close();
}
context.returnValue = gadget.transfer();