How Do I Save Changes The User Makes In An Editor Field To An External Data Source?
When Calling EditFieldText with 3 Parameters (Simpler)
When calling EditFieldText with all three parameters (which is what a data grid column does by default) the data grid will automatically save the text that the user enters in the dgData array. That means that all you need to do is save the text of the editor field to your external data source in the CloseFieldEditor message. Note that if you save anything other than the text of pFieldEditor then your data source will not match the dgData value.
Here is an example script that goes in the Data Grid group script.
## An example that saves
on CloseFieldEditor pFieldEditor
put the dgColumn of the target into theColumnBeingEdited
put the text of pFieldEditor into theNewText
## Save data to database using command I defined
put "Person" into theTable
## Get the unique id of the row in the database we want to edit
put GetDataOfIndex(the dgIndex of the target, "id") into theRowID
SaveDataToDatabase theTable, theRowID, theColumnBeingEdited, theNewText
end CloseFieldEditor
When Calling EditFieldText with 1 Parameter (More Flexible)
If you are working with data grid forms or decide to override the default behavior for data grid columns then you will make the call to EditFieldText yourself. For complete control over what gets saved you only pass in 1 parameter to EditFieldText. By passing in 1 parameter you are responsible for saving any changes to dgData.
Assume you made the following call in a data grid form:
EditFieldText the long id of field "Name" of me
CloseFieldEditor would still be sent when the user changes the contents of the field but would need to contain code for saving the changes to the dgData array.
Here is an example script that goes in the Data Grid group script.
## CloseFieldEditor placed in data grid script
on CloseFieldEditor pFieldEditor
put the dgColumn of the target into theColumnBeingEdited
## Store UTF8 text
put unidecode(the unicodetext of pFieldEditor, "UTF8") into theNewText
## Save data to database using command I defined
put "Person" into theTable
## Get the unique id of the row in the database we want to edit
put GetDataOfIndex(the dgIndex of the target, "id") into theRowID
SaveDataToDatabase theTable, theRowID, theColumnBeingEdited, theNewText
## Update dgData.
## Setting dgDataOfIndex will refresh the data grid display as well as update dgData
put the dgDataOfIndex[ the dgIndex of the target] of me into theDataA
put theNewText into theDataA[theColumnBeingEdited]
set the dgDataOfIndex[the dgIndex of the target] of me to theDataA
end CloseFieldEditor
Point of clarification:
in the examples, your step that actually does the DB save is told the table, the column and the new value... but not the row ID? Would this not update EVERY row, putting the new value in the selected column for ALL rows? Since I can't imagine that was the intent here, how indeed are you telling the DB to update just the one row you wanted to change?