|
Saving Data (CFMX) The Grid sends only the changes to data to the server for saving. It does this to save on bandwidth in order to maximize responsiveness and server performance. First, include the Nitobi Coldfusion XML library: <!--- We include the Nitobi CF XML library 1.0 ---> <cfinclude template = "nitobi.xml.cfm"> |
Next, make a call to EBASaveHandler_ProcessRecords() which grabs the updategram from the Ajax form post. <CFOUTPUT>
#EBASaveHandler_ProcessRecords()#
</CFOUTPUT> |
Now we loop through our updategram instructions and perform all the necessary INSERT's, UPDATE's, and DELETE's. <cfloop index = "InsertLoop" from = "1" to = #EBASaveHandler_ReturnInsertCount#> <cfquery datasource="NitobiTestDB" name="InsertRecord"> INSERT INTO tblContacts3k ( ContactName, ContactEmail, JobTitle, CompanyName, PhoneNumber, Address) VALUES ( '#EBASaveHandler_ReturnInsertField(InsertLoop, "ContactName")#', '#EBASaveHandler_ReturnInsertField(InsertLoop, "ContactEmail")#', '#EBASaveHandler_ReturnInsertField(InsertLoop, "JobTitle")#', '#EBASaveHandler_ReturnInsertField(InsertLoop, "CompanyName")#', '#EBASaveHandler_ReturnInsertField(InsertLoop, "PhoneNumber")#', '#EBASaveHandler_ReturnInsertField(InsertLoop, "Address")#') </cfquery> </cfloop> |
Now we process our update records. EBA_PK is the primary key of the row. <cfloop index = "UpdateLoop" from = "1" to = #EBASaveHandler_ReturnUpdateCount#> <cfquery datasource="NitobiTestDB" name="UpdateRecord"> UPDATE tblContacts3k SET ContactName = '#EBASaveHandler_ReturnUpdateField(UpdateLoop, "ContactName")#', ContactEmail = '#EBASaveHandler_ReturnUpdateField(UpdateLoop, "ContactEmail")#', JobTitle = '#EBASaveHandler_ReturnUpdateField(UpdateLoop, "JobTitle")#', CompanyName = '#EBASaveHandler_ReturnUpdateField(UpdateLoop, "CompanyName")#', PhoneNumber = '#EBASaveHandler_ReturnUpdateField(UpdateLoop, "PhoneNumber")#', Address = '#EBASaveHandler_ReturnUpdateField(UpdateLoop, "Address")#' WHERE ContactID = #EBASaveHandler_ReturnUpdateField(UpdateLoop, "EBA_PK")# </cfquery> </cfloop> |
Finish by processing our delete instructions.. <cfloop index = "DeleteLoop" from = "1" to = #EBASaveHandler_ReturnDeleteCount#> <cfquery datasource="NitobiTestDB" name="DeleteRecord"> DELETE FROM tblContacts3k WHERE ContactID = #EBASaveHandler_ReturnDeleteField(DeleteLoop, "EBA_PK")# </cfquery> </cfloop> |
Finally, we complete the process by calling CompleteSave. <cfscript> EBASaveHandler_CompleteSave(); </cfscript> |
Comments:
|
Note: This article was taken from the Nitobi knowledgebase. To search the knowledgebase, go to http://www.nitobi.com/kb/.
|
All content is Copyright 2005, Nitobi Software Ltd. Direct all inquiries to [email protected].
|