barrymavin
2013-03-07, 23:01
The data mapping is all now in place in RC4.
In the attributes for a field or grid column you have two new attributes:
"Get data mapping" and "Set data mapping".
So how does it all work you may ask.
Let me explain.
These attributes should be expressions. Let's say you have a numeric value that you want to display formatted as currency.
In the "Get data mapping" specify:
// The second (optional) argument to the currency() function is the number of decimal places.
currency( {} , 4)
This will display the numeric field as e.g. $12,675.4523
Now to edit this and be able to "map" it back into the way it is stored in the database, we specify a "Set data mapping" expression:
// val( ) will strip commas and $ out for us automatically
val( "{}" )
Ok... so now you want to map a numeric "order id" to its description in another table using a foreign key. The KeyLookup() function can do this for us as it will save and restore the cursor state (record position) so as not to affect other parts of the App.
It will also open the table if its not already open but better to open it in the init or load delegate yourself so it does not keep opening and closing it for each keylookup it does.
In the "Get data mapping" specify:
// keylookup(table|alias, indextagname, key, valueExpr)
keylookup("orderdetails" , "orderdid", {}, orderdescription)
In the "Set data mapping" specify:
// keylookup(table|alias, indextagname, key, valueExpr)
keylookup("orderdetails" , "orderddescription", "{}", orderid)
Notice how {} are used to substitute the value to be mapped in the mapping expressions.
If you want to be clever you can call one of your own functions in a custom library and pass "{}" as a parameter to it.
To edit the "Foreign key" value you could specify a choice list using SQL SELECT to populate the combobox control. The mapping to and from the database/table column will be handled for you.
Thats basically it.
In the attributes for a field or grid column you have two new attributes:
"Get data mapping" and "Set data mapping".
So how does it all work you may ask.
Let me explain.
These attributes should be expressions. Let's say you have a numeric value that you want to display formatted as currency.
In the "Get data mapping" specify:
// The second (optional) argument to the currency() function is the number of decimal places.
currency( {} , 4)
This will display the numeric field as e.g. $12,675.4523
Now to edit this and be able to "map" it back into the way it is stored in the database, we specify a "Set data mapping" expression:
// val( ) will strip commas and $ out for us automatically
val( "{}" )
Ok... so now you want to map a numeric "order id" to its description in another table using a foreign key. The KeyLookup() function can do this for us as it will save and restore the cursor state (record position) so as not to affect other parts of the App.
It will also open the table if its not already open but better to open it in the init or load delegate yourself so it does not keep opening and closing it for each keylookup it does.
In the "Get data mapping" specify:
// keylookup(table|alias, indextagname, key, valueExpr)
keylookup("orderdetails" , "orderdid", {}, orderdescription)
In the "Set data mapping" specify:
// keylookup(table|alias, indextagname, key, valueExpr)
keylookup("orderdetails" , "orderddescription", "{}", orderid)
Notice how {} are used to substitute the value to be mapped in the mapping expressions.
If you want to be clever you can call one of your own functions in a custom library and pass "{}" as a parameter to it.
To edit the "Foreign key" value you could specify a choice list using SQL SELECT to populate the combobox control. The mapping to and from the database/table column will be handled for you.
Thats basically it.