02-24-2020, 06:26 PM
Code:
on mouseUp
local tKeys, tOutputA, tCount, tDataA
//CLEAR datagrid
set the dgData of group "datagrid" to empty
//GET ALL THE KEYS OF THE TABLE
put cdb_tableKeys("testTable") into tKeys
//GET ALL RECORDS OF THE TABLE
put cdb_read("testTable", "*", "cloud") into tOutputA
put 0 into tCount
//REPEAT FOR EVERY RECORD SO WE CAN CREATE AN ARRAY FORMATTED FOR datagrid
repeat for each key xRecordID in tOutputA
add 1 to tCount
//GRAB THE RECORDID SO WE CAN DISPLAY IT
put xRecordID into tDataA[tCount]["recordID"]
//REPEAT FOR EVERY KEY IN THE TABLE SO WE CAN DISPLAY ALL COLUMNS OF THE RECORDS
repeat for each item xKeyName in tKeys
put tOutputA[xRecordID][xKeyName] into tDataA[tCount][xKeyName]
end repeat
end repeat
//POPULATE datagrid
set the dgData of group "datagrid" to tDataA
end mouseUp
I added comments to the code. I hope it's easier to understand. Let me know if you have any questions.
For your case, place the code in the preOpenCard. If your expense table only has the two keys expenseName and expenseAmount then you shouldn't need to modify the code. If you have more keys but only want to display those two then replace:
put cdb_tableKeys("testTable") into tKeys
with
put "expenseName,expenseAmount" into tKeys
If you don't want to display the recordID remove or comment out:
put xRecordID into tDataA[tCount]["recordID"]