Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Inserting with CFGRID in CF 9

New Here ,
Nov 05, 2009 Nov 05, 2009

I've noticed Coldfusion 9 seems to support inserting records with CFGRID

Heres an example Im working on

<cfgrid format="html" name="grid01" pagesize=20 autoWidth="true" width="925"

            stripeRows=true stripeRowColor="silver"

            bind="cfc:getStuff.getData({cfgridpage},{cfgridpagesize},

                {cfgridsortcolumn},{cfgridsortdirection})"

            delete="no" selectmode="edit"

insert="true"

onchange="cfc:modifyStuff.editData({cfgridaction},{cfgridrow},{cfgridchanged})">

There are of course columns included below.

What I'm trying to do is figure out how to make that empty row you get (when you click insert at the bottom of the grid) actually insert that information as a new row.

Here is my corresponding CFC for updating/editing data (which works fine for edits):

<cffunction name="editData" access="remote" output="true" roles="Admin,PAM">

    <cfargument name="gridaction">

    <cfargument name="gridrow">

    <cfargument name="gridchanged">

    <cfif isStruct(gridrow) and isStruct(gridchanged)>

        <cfif gridaction eq "U">

            <cfset colname=structkeylist(gridchanged)>

            <cfset value=structfind(gridchanged,#colname#)>

            <cfquery name="updateAssets">

                update table set <cfoutput>#colname#</cfoutput> =

                    '<cfoutput>#value#</cfoutput>'

                where id = <cfoutput>#gridrow.Id#</cfoutput>

            </cfquery>

</cfif>

</cfif>

</cffunction>

Is there another gridaction value that corresponds to inserting? I couldn't find any example online of doing this in CF 9 without using an insert button instead of a new row. Seems like this should be built in.

2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2010 Jun 22, 2010

Hey.. I have the same question.. Were you able to figure out anything?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2010 Jun 25, 2010
LATEST

Yeah. It works, but there doesn't seem to be any official documentation on it.

Here is an example in my code that is a function in a CFC that allows users to modify and insert rows in a grid. The key is gridaction eq "I"

<cffunction name="editRows" access="remote" output="true" roles="Admin" returntype="string"

hint="Allows modification of rows in bulk through the CFGRID">

    <cfargument name="gridaction">

    <cfargument name="gridrow">

    <cfargument name="gridchanged">

<cfset var colname = structkeylist(gridchanged)>

    <cfset var value = structfind(gridchanged,#colname#)>

  <cfif isStruct(gridrow) and isStruct(gridchanged)>

        <cfif gridaction eq "U">

            <cfquery name="updateRows">

                UPDATE RECORDS SET #COLNAME# = <cfqueryparam value="#value#" CFSQLType = "CF_SQL_VARCHAR"  >

                WHERE ROW_ID = <cfqueryparam value="#gridrow.ROW_ID#" CFSQLType = "CF_SQL_INTEGER">

            </cfquery>

<cfelseif gridaction eq "I">

<cfquery name="insertRow">

                INSERT INTO RECORDS (ROW_ID, ROW_COL1,ROW_COL2)

VALUES ('#gridrow.ROW_ID#',

'#gridrow.ROW_COL1#',

'#gridrow.ROW_COL2#'

)

 

</cfquery>

</cfif>

</cfif>

</cffunction>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources