Purpose You want to work with a GuiXT table variable in JavaScript as an array. |
Solution
Example:
InputField (5,87)
"Customer" (5,107) _
Table (8,71)
(23,137) title="Sales"
_
Column "Description"
table="salesorders" _
Column "Price"
table="salesorders" _
InputScript script
CreateStructure V[return] _
// items
Set V[SALESORG] "1010"
// read order
CallJS read_sales "salesorders" return
JavaScript
unction read_sales(mytable) { // Convert GuiXT table to JavaScript object var myobj = JSON.parse(guixt.Get(mytable)); /**********/ /* Example: myobj = { { "SHORT_TEXT":"Pump 123", "NET_VALUE":55.12 }, { "SHORT_TEXT":"Engine XY", "NET_VALUE":4892.12 } }; */ // For each row in the table do... for (var i = 0; i < myobj.length; i++) { // Get the string at row i, column "NET_VALUE" // and convert it to a number var value = parseFloat(myobj[i]["NET_VALUE"]); // Round the value to an integer value = Math.round(value); // Append some text text = value + " €"; // Write the new string back to the "cell" myobj[i]["NET_VALUE"] = text; } // Save the number of rows guixt.set("rowsCount", myobj.length); // Convert our javascript object back to the GuiXT table variable var mysales = JSON.stringify(myobj); // Update the guixt table variable guixt.Set(mytable, mysales); } |
Components InputAssistant + Controls |