coldfusiondynamic-datacoldfusion-8cfgrid

Editing and updaing cfgrid values dynamically


I need to edit the values of one (or more) column in the cfgrid by double-clicking the value and on pressing enter the cfgrid should update the db with the new value.

I have seen this capability in the flex datagrid . A similar capability is expected.

Any help is appreciated.


Solution

  • I am newbie to CF so i finally found out how you do that: you need to add the attribute selectMode=edit and moreover you need to add the onchange attribute. eg: onchange = "cfc:getCalculatorData.editCategory({cfgridaction},{cfgridrow},{cfgridchanged})">

    Further you write your update query in the cfc editLocation

    Example for the cfc function is :

        <cfif isStruct(gridrow) and isStruct(gridchanged)>
            <cfif gridaction eq "U">
                <cfset colname=structkeylist(gridchanged)>
                <cfset value=structfind(gridchanged,#colname#)>
                <cfquery name="team" datasource="batcalc"> 
                    UPDATE tbl_category SET <cfoutput>#colname#</cfoutput> = 
                        '<cfoutput>#value#</cfoutput>'
                    WHERE category_id = <cfoutput>#gridrow.category_id#</cfoutput>
                </cfquery>
            <cfelse>
                <cfquery name="delCat" datasource="batcalc"> 
                    DELETE FROM tbl_category 
                    WHERE category_id = <cfoutput>#gridrow.category_id#
                        </cfoutput>
                </cfquery> 
            </cfif>
        </cfif>
    </cffunction>