Updating and Adding Records Being Displayed In ColdFusion 8's cfgrid

Introduction:

The CF 8 Developer's Guide (pages 630-635) discusses the new cfgrid tag. I was especially interested in how to update cfgrid's data provider by changing the values displayed in the grid and by adding a new record to the underlying data. The developer's guide provides an example of how to update the data source for values displayed by the cfgrid. However, the documentation explains that "you cannot insert new rows directly in a grid...To add rows you must enter the data in a form, and make sure the grid refreshes after the form has been submitted." (page 633) Unfortunately, there is no example in the developer's guide of how to do that, so I created my own example code (based somewhat on the cfgrid update example provided in the developer's guide). To view a working version see: /cf8test/employees.cfm.

Discussion:

My example (download the code) shows the user a new employee form and a grid showing the current employees. You can fill out the new employee form and insert the data into the data provider. The grid showing the employees will be refreshed and display the new employee. If you want to change any of the values shown in the current form you can click on a field's value and type in a new value.

You can download my source code (a zip with two files: employees.cfm and employeeService.cfc). Just extract both files to the same folder and then use your browser to open the employees.cfm file.

Below are some excerpts from the example that I believe might need some explanation.

When you click on the Add Employee button, the following JavaScript function is executed.


function doInsertEmployee() {
    
/*
arguments are form name, cfc and method to send form values to, javascript function to handle result,
javascript function to handle error
*/

ColdFusion.Ajax.submitForm('insertForm', 'employeeService.cfc?method=insertData', resultInsertHandler, insertErrorHandler);
         
}

The ColdFusion.Ajax.submitForm function submits the form field values of the form named insertForm to the insertData function in the employeeService CFC. The JavaScript function resultInsertHandler is executed if everything works ok and the insertErrorHandler JavaScript function is called if there was a problem. Thanks to Dave Ferguson for insight on how to submit the form directly to a CFC function.

In the JavaScript function resultInsertHandler, I merely add a message saying the record was added and then clear the form field values so new values can be typed in. I also have the cfgrid refresh itself to display the new record. You can refresh the cfgrid using this JavaScript command: ColdFusion.Grid.refresh('employeeGrid', true); employeeGrid is the name of the cfgrid and true means keep the cfgrid on its current page.

Please note that in this example code, I'm not validating the user's input. Whatever the user inputs into the form is just sent to the insertData function in the EmployeeService CFC. Also the example code is very plain vanilla. Hopefully, the example code helps you understand how to add a record to data being displayed in a cfgrid.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
As I'm just beginning to add this to http://www.coldfusionbloggers.org, this is perfect timing. :) Can you please make the change described here:

http://www.coldfusionjedi.com/index.cfm/2007/7/26/...
# Posted By Raymond Camden | 8/9/07 4:38 AM
Great example. It is crazy how easy it is.

Thanks for the info.
# Posted By Steve Sequenzia | 8/9/07 7:32 AM
Is it possible to have select boxes in the cfgrid? I'm not running CF8 yet, so I can't try it out.
# Posted By Jeff | 8/14/07 7:33 AM
Jeff - I don't know. You'll have to research the CF 8 documentation. Also read through the cfgrid examples posted on Ray Camden's blog. You could also search through the ColdFusion group on Yahoo.com.
# Posted By Bruce | 8/14/07 8:25 AM
I've been using this example to learn from and am trying to adapt it but getting issues on the insert function.

This doesn't work:

<cffunction name="insertData" access="remote" output="false" returntype="void">

<cfargument name="emp_id">
   <cfargument name="firstName">
   <cfargument name="lastName">
   <cfargument name="email">
   <cfargument name="company">
         
   <cfquery name="team" datasource="flashy">
      
      insert into employees (emp_id, firstname, lastname, email, company)
      values (
      
         <cfqueryparam cfsqltype="cf_sql_integer" value="#emp_id#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#firstName#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#lastName#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#email#">
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#company#">
            
      )

   </cfquery>
      
   
</cffunction>

But this one does. The field names are ok because the select and datagrid work with the company added.

<cffunction name="insertData" access="remote" output="false" returntype="void">

<cfargument name="emp_id">
   <cfargument name="firstName">
   <cfargument name="lastName">
   <cfargument name="email">
         
   <cfquery name="team" datasource="flashy">
      
      insert into employees (emp_id, firstname, lastname, email)
      values (
      
         <cfqueryparam cfsqltype="cf_sql_integer" value="#emp_id#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#firstName#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#lastName#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#email#">
            
      )

   </cfquery>
      
   
</cffunction>

Can someone let me know what I am missing?

Cheers
Peter
# Posted By Peter | 8/18/07 12:57 AM
After this line in your first example:

<cfqueryparam cfsqltype="cf_sql_varchar" value="#email#">

you're missing the comma. Should be:

<cfqueryparam cfsqltype="cf_sql_varchar" value="#email#">,

since there is another cfqueryparam after that one
# Posted By Bruce | 8/18/07 6:58 AM
Ah, yes, well there was two hours i have wasted on a comma - really must check my code properly next time!

Your a godsend. All good now.

Cheers
Peter
# Posted By Peter | 8/18/07 7:01 AM
All very nifty, thanks for the example.

Any idea how to get the number of records returned by the cfc (TOTALROWCOUNT in the data) from the grid.

I wanted to bind an input box or something to a paged grid so I new what the whole record set size was not just the number of pages.
# Posted By Doug Cain | 9/2/07 1:49 PM
Doug - I've not done that. When I get some time I'll research it.
# Posted By Bruce Phillips | 9/4/07 2:06 PM
Well Bruce,

I have to say, from around the CF community, you have taken the CFGrid example to the next level, wow. I was bouncing around the links form the other CF bloggers, and I found this example. I was working on an application and could not figure out how to make the edits inline with the CFGrid. Thanks for your knowledge base & posting the sourse, I was able to make the adjustments to my application, and it worked fine.

Thanks again

Camilo
# Posted By Camilo | 9/10/07 4:41 AM
Great example! Thanks.

Does anyone know how to put a confirmation alert on the delete button in cfgrid? I can see people accidentally deleting records they didn't mean to!!
# Posted By Bruce Van Horn | 10/16/07 5:06 AM
I dig a little deeper into the Ext javascript object and figured out how to use javascript to edit a single cell and refresh a single row without having to use ColdFuison.Grid.Refresh and loose the row you have selected. I saw this thread yesterday and thought people might be interested. I blogged about it here:

http://www.coldfusionguy.com/ColdFusion/blog/index...
# Posted By Scott Bennett | 11/2/07 3:49 PM
Scott - I took a look at your blog entry and example. Very good work and it will be quite useful. Thanks for letting me know.
# Posted By Bruce | 11/2/07 6:15 PM
Does anyone know if/why the Adobe Developers Guide Example used in your "editData" function does not cfqueryparam the variables? Is it an oversight or is it because there isn't enough information coming into the function to properly param them?

Excellent post and example. :-)
# Posted By Dan | 11/14/07 12:29 PM
@Dan,

My guess would be that they just want to keep the examples as simple as possible to demonstrate the point they are trying to communicate without cluttering the example code. I do know that Adobe does highly recommend the use of cfparam and cfqueryparam to validate any user submitted data.
# Posted By Scott Bennett | 11/14/07 4:20 PM
If I have an Application.cfc based on Ray Camden's example in the same folder as the employeeService.cfc it kills the grid. I get a "Error:widget: CFGrid: Response is empty" from cfdebug. Something in the application is killing the response.

Has anyone else run into this? Is there a way to disable application.cfc specifically for the employeeService.cfc? Maybe there is a way to place employeeService.cfc outside of this application folder and reference it there. (any idea of the syntax to reference a CFC that's up one folder?)

Overall, thank you for this great example! :-) When I don't add application.cfc it works great. It's amazing what can be accomplished in so little code.
# Posted By Dan | 11/15/07 11:45 AM
To update my own question/comment...

If I place my employees.cfm file along with my application.cfc inside a folder called, "/user/employees.cfm" and then place my employeeService.cfc on the root...

Inside employees.cfm I can update the reference to the cfc with a leading slash as shown below and it will work properly since the Application.cfc will not interfere:

bind="cfc:/employeeService.cfc.getData( ...(rest of the path is the same)

Based on this example, it could be placed in any other folder outside of my application folder. I'm not sure if there is a better way to reference the application than this path relative to the root.
# Posted By Dan | 11/15/07 11:51 AM
You should probably just delete the onRequest - it tends to get in the way.
# Posted By Raymond Camden | 11/15/07 11:58 AM
Ray's right, application.onRequest() was doing something to prevent a good response from cfc:employeeService.getData(...

Once that function was removed from his example application.cfc, this example worked perfectly. :-)
# Posted By Dan | 11/15/07 12:29 PM
I would like to say thank you for this useful article.
# Posted By mehmet Poyraz | 12/15/07 11:39 PM
Bruce (or anyone else) - I've got a question re: passing parameters to CFCs when they're part of a bind expression. Suppose in your examples that employees were divided into different Departments and that when the form loaded, you wanted to display only employees from a specified department. Suppose the desired departments was stored in perhaps a hidden field in form01 and was named DeptID.

In your CFC's getData() function, you'd need to pass the DeptID value as an additional parameter. What is the proper syntax for including this parameter when you call getData() in the bind parameter of the cfgrid tag?

What if the DeptID was not in a form field but was in the URL or some other scoped variable (e.g. session variable)?
# Posted By leon chalnick | 12/20/07 6:09 PM
Okay...just answered my own question, partially.

If the DeptID was in a form field in form01, then you'd pass it like this:

<cfgrid
name="employeeGrid"
...
bind="cfc:employeeService.getData({form01:DeptID},{cfgridpage},..."
...
>
# Posted By leon chalnick | 12/20/07 6:22 PM
Hi.
Does anyone know how to pass a variable from URL eg. an ID named URL.ID in the bind option in cfgrid?

trying my best...
# Posted By Garth | 1/31/08 4:53 AM
Garth - see Leon's comment right above your comment. Could you use {URL:ID}?
# Posted By Bruce | 2/1/08 12:58 PM
I'm having similar problems passing URL variables into the CFGRID. my main page refreshes the URL variables each time a filtering decision is made, and the GRID should refresh each time with new URL variables. How can I pass them into the CFGRID?

And do I need the CFPARAMs?

<CFFORM>
   <CFGRID NAME="GetMemberDataForDirectory"
      FORMAT="HTML"
PAGESIZE="#URL.SHOWROWS#"
STRIPEROWS="YES"
APPENDKEY="YES"
HREF="/index.cfm?fuseaction=members.emailmember"
HREFKEY="ENCRYPTARCODE"
WIDTH="100%"
   BIND="cfc:memberDirectory.getMembers(
               {URL:equitytype},
{cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection}
)">
<CFGRIDCOLUMN NAME="lastname" HEADER="Last Name" WIDTH="100"/>
<CFGRIDCOLUMN NAME="firstname" HEADER="First Name" WIDTH="100"/>
<CFGRIDCOLUMN NAME="City" HEADER="Home City" WIDTH="125">
<CFGRIDCOLUMN NAME="State" HEADER="State" WIDTH="50">
<CFGRIDCOLUMN NAME="equitytype" HEADER="Type" WIDTH="50">
<CFGRIDCOLUMN NAME="emailme" HEADER="CONTACT">
<CFGRIDCOLUMN NAME="ENCRYPTARCODE" DISPLAY="NO" HEADER="ENCRYPTARCODE">
</CFGRID>
</CFFORM>

<CFCOMPONENT OUTPUT="false">
<CFPARAM NAME="url.initial" DEFAULT="">
<CFPARAM NAME="url.state" DEFAULT="">
<CFPARAM NAME="url.equitytype" DEFAULT="all">

<!--- Get Members --->
<CFFUNCTION NAME="getMembers" ACCESS="remote" RETURNTYPE="struct">
<CFARGUMENT NAME="page" TYPE="numeric" REQUIRED="yes">
<CFARGUMENT NAME="pageSize" TYPE="numeric" REQUIRED="yes">
<CFARGUMENT NAME="gridsortcolumn" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="gridsortdir" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="equitytype" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="initial" TYPE="STRING" DEFAULT="#url.initial#">

<!--- Local variables --->
<CFSET var GetMemberDataForDirectory="">

<!--- Get data --->
<CFQUERY NAME="GetMemberDataForDirectory" DATASOURCE="ORCIntranet">
SELECT ARCODE,Lastname, Firstname, City, State, equitytype, EMAIL
FROM view_familyinfo_all_activemembers_withcontactinfo
    WHERE FAMNUM <= '2' AND MISC1 <> '' and MISC1 BETWEEN '100' and '599'
<CFIF arguments.initial NEQ ''>AND LEFT(Lastname,1) = '#arguments.initial#'</CFIF>
<CFIF URL.state NEQ ''>AND STATE = '#URL.state#'</CFIF>
<CFIF URL.equitytype EQ 'equity'>AND MISC1 IN ('400','500')</CFIF>
<CFIF ARGUMENTS.gridsortcolumn NEQ "" and ARGUMENTS.gridsortdir NEQ "">
ORDER BY #ARGUMENTS.gridsortcolumn# #ARGUMENTS.gridsortdir#
</cfif>
</CFQUERY>

<!--- And return it as a grid structure --->
<CFRETURN QueryConvertForGrid(GetMemberDataForDirectory,
ARGUMENTS.page,
ARGUMENTS.pageSize)>
</CFFUNCTION>

</CFCOMPONENT>
# Posted By Jonathan | 3/5/08 3:03 PM
Jonathan - I sincerely apologize but I'm swamped at work right now and don't have the time to analyze your code.
# Posted By Bruce | 3/6/08 6:39 PM
no problem, TOTALLY understand. I'm just appreciative of all you've built and posted already!

I got help from http://experts-exchange (be sure you include that hyphen - haha) and here's the deal, for other users' benefit:

HURRAY!!!! so simple...
argh

they keys i was missing were
1. the <CFINPUT tag type=hidden name=MyURLVar> that transformed each url variable into a form variable, which was then in:
2. the BIND attribute which needs each var defined to be pushed to the CFC specified.
3. on the CFC of course each user variable needs CFARGUMENT definition and the SQL code uses ARGUMENT var prefixes.

FORM PAGE:
<CFFORM>
   <CFINPUT NAME="equitytype" TYPE="HIDDEN" VALUE="#url.equitytype#">
   <CFINPUT NAME="state" TYPE="HIDDEN" VALUE="#url.state#">
   <CFINPUT NAME="initial" TYPE="HIDDEN" VALUE="#url.initial#">
   <CFGRID NAME="GetMemberDataForDirectory"
      FORMAT="HTML"
PAGESIZE="#URL.SHOWROWS#"
STRIPEROWS="YES"
SELECTONLOAD="FALSE"
APPENDKEY="YES"
HREF="/index.cfm?fuseaction=members.emailmember"
HREFKEY="ENCRYPTARCODE"
WIDTH="100%"
   BIND="cfc:memberDirectory.getMembers(
               {cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection},
'#URL.equitytype#',
'#URL.state#',
'#URL.initial#'
)">
<CFGRIDCOLUMN NAME="lastname" HEADER="Last Name" WIDTH="100"/>
<CFGRIDCOLUMN NAME="firstname" HEADER="First Name" WIDTH="100"/>
<CFGRIDCOLUMN NAME="City" HEADER="Home City" WIDTH="125">
<CFGRIDCOLUMN NAME="State" HEADER="State" WIDTH="50">
<CFGRIDCOLUMN NAME="equitytype" HEADER="Type" WIDTH="50">
<!---<CFGRIDCOLUMN NAME="misc1" HEADER="misc1" WIDTH="50">--->
<CFGRIDCOLUMN NAME="emailme" HEADER="CONTACT">
<CFGRIDCOLUMN NAME="ENCRYPTARCODE" DISPLAY="NO" HEADER="ENCRYPTARCODE">
</CFGRID>
</CFFORM>


CFC:
<CFCOMPONENT OUTPUT="false">
<!--- Get Members --->
<CFFUNCTION NAME="getMembers" ACCESS="remote" RETURNTYPE="struct">
<CFARGUMENT NAME="page" TYPE="numeric" REQUIRED="yes">
<CFARGUMENT NAME="pageSize" TYPE="numeric" REQUIRED="yes">
<CFARGUMENT NAME="gridsortcolumn" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="gridsortdir" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="equitytype" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="state" TYPE="string" REQUIRED="no" DEFAULT="">
<CFARGUMENT NAME="initial" TYPE="string" REQUIRED="no" DEFAULT="">

<!--- Local variables --->
<CFSET var GetMemberDataForDirectory="">

<!--- Get data --->
<CFQUERY NAME="GetMemberDataForDirectory" DATASOURCE="ORCIntranet">
SELECT ARCODE,Lastname, Firstname, City, State, equitytype, MISC1, EMAIL, CASE WHEN EMAIL LIKE ('%@%') THEN 'EMAIL'+' '+Firstname ELSE 'NO EMAIL' END AS EMAILME, CONVERT(VARCHAR, (ARCODE * 37))+CONVERT(VARCHAR, (FAMNUM * 37)) AS ENCRYPTARCODE
FROM view_familyinfo_all_activemembers_withcontactinfo
    WHERE FAMNUM <= '2' AND MISC1 <> '' and MISC1 BETWEEN '100' and '599'
<CFIF arguments.equitytype EQ 'equity'>AND MISC1 IN ('400','500')</CFIF>
<CFIF arguments.equitytype EQ 'social'>AND MISC1 IN ('100','109','110','150','159','160','300','360')</CFIF>
<CFIF arguments.equitytype EQ 'legacy'>AND MISC1 IN ('130','420','430','520','530')</CFIF>
<CFIF arguments.initial NEQ ''>AND LEFT(Lastname,1) = '#arguments.initial#'</CFIF>
<CFIF arguments.state NEQ ''>AND STATE = '#arguments.state#'</CFIF>
<CFIF ARGUMENTS.gridsortcolumn NEQ "" and ARGUMENTS.gridsortdir NEQ "">
ORDER BY #ARGUMENTS.gridsortcolumn# #ARGUMENTS.gridsortdir#
<CFELSE>
ORDER BY Lastname,ARCODE,FAMNUM
</cfif>
</CFQUERY>

<!--- And return it as a grid structure --->
<CFRETURN QueryConvertForGrid(GetMemberDataForDirectory,
ARGUMENTS.page,
ARGUMENTS.pageSize)>
</CFFUNCTION>

</CFCOMPONENT>
# Posted By Jonathan | 3/7/08 6:58 AM
I'm new at AJAX and ColdFusion. I was wondering if from the CFC you can return a specific value for 'message' for the java script function insertErrorHandler(id, message).

What I am trying to do is have conditionals inside the CFC once they edit the data and if the conditional breaks, return an error message.

Example: "Employee cannot be edited because they are inacative."

Thanks in advance.
# Posted By Jimmy | 3/25/08 3:52 PM
I downloaded the zip and put both files in the same directory, but when I load employees.cfm I get this message:

Error invoking CFC /employeeService.cfc :Not Found

How does it not find it? It is in the same directory

CF8 BTW.
# Posted By John Mosey | 4/4/08 2:12 PM
John - I just tested the code by downloading the zip file from the blog entry and unzipping both files into the same folder. I did not have a problem running employees.cfm in CF 8.

Do you have a data source named cfdocexamples (which is a default data source installed with CF 8)?
# Posted By Bruce | 4/4/08 2:45 PM
I've had a problem using cfgrid. I tried your example and got the same results I get every time I try to use it. I can only bind to a URL. Binding to a CFC component function doesn't work. Has to be my environment, but I can't find it. I know lots of others have this problem also but no one seems to be able to get around it. I t sure would be handy to use the CFC function.
# Posted By vaughn | 4/6/08 6:29 PM
I also got this message:

Error invoking CFC /employeeService.cfc :Not Found

Use:coldfusion 8
# Posted By manoj | 5/1/08 3:34 AM
Manoj - I don't understand your comment. I tested the code and everything is working well.
# Posted By Bruce | 5/1/08 8:24 AM
When I change the header to <cfgridcolumn name="Emp_ID" display=true header="Employee <br /> ID"/> the color of the header changes from grey to tan. Is there any way to add multiple lines to the header and keep the grey color?
# Posted By mp | 5/2/08 12:51 PM
I have initial display of cfgrid working. Looks great, but when I click on a column header I get this error:

Error Executing Database Query.[Macromedia][SQLServer JDBC Driver][SQLServer]String or binary data would be truncated.

I have downloaded serveral sample files, and get this error with each. I am wondering if I have missed something is administrator? Any suggestions would be greatly appreciated.
# Posted By Cheryl Dunn | 6/2/08 12:36 PM
I keep getting Java errors such as 'ColdFusion' is undefined and 'Ajax' is undefined. I'm very new to CFCs as I'm coming from CF4.5, so hopefully it's an easy fix. What's wrong?
# Posted By Kate | 7/2/08 11:41 AM
Is it possible to add a drag, clone that row while dragging & drop to the next row kinda functionality to this grid? My grid is going to have multiple rows with almost same data with some minor changes. So instead of letting the users use the form every time to fill the same data, it would be good to have a clone functionality..could someone shed some light?
# Posted By sneha | 7/29/08 12:43 PM
Thank you soooooooo much !!!

Great simple working example !!! and code !
# Posted By Guy Sagy | 8/26/08 5:44 PM
hi... i downloaded your sample in my computer and it works perfectly here in localhost. but when uploaded to a Linux Server, with same Database and cf pages... it doesnt work.. it says CFGRID : Response is empty.. what seems to be wrong with this? can u pls help me...??? i needed it badly. thanx
# Posted By carlo | 9/10/08 7:14 PM
I found the sample code here to be amazing and it helped me tremendously with an app i'm working on but I cannot for the life of me figure out how to rig it so I can pass in some variables (whID, whichWeek) to the "getData" function to use in the where clause.

<cfform name="form01">
      <cfgrid format="html" name="recordGrid" pagesize=11 stripeRows=true stripeRowColor="gray" width="700"
         bind="cfc:hourService.getData({cfgridpage},{cfgridpagesize},
         {cfgridsortcolumn},{cfgridsortdirection},#selectForm.whID#)"
         delete="yes" selectmode="edit" deletebutton="Unassign"
         onchange="cfc:hourService.editData({cfgridaction},{cfgridrow},{cfgridchanged})">
         <cfgridcolumn name="whid" display=true header="WebHawk ID"/>   
         <cfgridcolumn name="ptrecordno" display=true header="PT Record No."/>   
         <cfgridcolumn name="employee" display=true header="Employee"/>
         <cfgridcolumn name="projectTitle" display=true header="Project Title">
         <cfgridcolumn name="sunday" display=true header="sunday"/>
      </cfgrid>
   </cfform>

   <cfform name="selectForm" format="html" >
   
      <table class="addTable">
       <tr>
         <td><div align="right">Employee:</div></td>
         <td>      
          <div align="left">
          <cfselect enabled="No" name="whID" multiple="no" query="getEmployees" display="empSel" value="whID">            
       </cfselect>
</div>
          </td>
       <td><div align="right"><A HREF="#"
onClick="cal.select(document.forms['selectForm'].whichWeek,'anchor1','MM/dd/yyyy'); return false;"
NAME="anchor1" ID="anchor1">SELECT</A></div></td>
<td><div align="left">
<cfinput type="text" name="whichWeek" value="Week Ends On" size="20">
</div></td>
       </tr>
      </table>
      <cfinput type="button" name="assign" value="Assign" onClick="doSelect('hourService');" class="addButton"/>
      
   </cfform>

      function doSelect(whichCFC) {
   
    /*
    arguments are form name, cfc and method to send form values to, javascript function to handle result,
    javascript function to handle error
    */
    ColdFusion.Ajax.submitForm('selectForm', 'functions/' + whichCFC + '.cfc?method=getData', resultSelectHandler, selectErrorHandler);
       
   }

<cffunction name="getData" access="remote" output="false" returntype="any">

   <cfargument name="page" default="1">
   <cfargument name="pageSize" default="11">
   <cfargument name="gridsortcolumn" default="">
   <cfargument name="gridsortdirection" default="">
   
   <cfargument name="whichWeek" default="06/03/1971">
   <cfargument name="whID" default="">
   <cfset sunday = DateFormat(whichWeek,"yyyy-mm-dd")>
   <cfset saturday = DateFormat(DateAdd("d",-1,whichWeek),"yyyy-mm-dd")>
   
   <cfquery name="team" datasource="webhawk">
      select employee_task.whid as whid, employee_task.ptrecordno as ptrecordno, employee.lastName as employee, projectTitle,
      

      
      sun.hours as sunday
      from employee_task
      
      join employee on
      employee.whid = employee_task.whid
      
      join task on
      task.ptRecordNo = employee_task.ptRecordNo
      

      left join
      (select hours, dateof, whid, ptRecordNo
      from hours
      where dateof = '#sunday#') as sun
      on
      employee_task.whid = sun.whid
      and employee_task.ptrecordNo = sun.ptrecordno
      
      where employee_task.whid = '#whID#'
   
      <cfif gridsortcolumn neq "" or gridsortdirection neq "">
      order by #gridsortcolumn# #gridsortdirection#
      </cfif>
   
   </cfquery>
   
   <cfreturn QueryConvertForGrid(team, page, pageSize)>
   
</cffunction>
# Posted By rob | 9/30/08 2:54 PM
(Some of the applications on that web page and other intranet ones)
Checkboxes and boolean code for updating that worked

   <cfset mybool = 1>
<cfset nobool = 0>
   <cfif isStruct(gridrow) and isStruct(gridchanged)>
   
      <cfif gridaction eq "U">
      
         <cfset colname=structkeylist(gridchanged)>
         <cfset value=structfind(gridchanged,#colname#)>
         
         <cfquery name="qryTopics" datasource="er2000">
         
            update LU_eLibraryTopics
            <cfif isBoolean(value)>
   <cfif value EQ "true">
set #colname# = #mybool#
<cfelse>
set #colname# = #nobool#
</cfif>
            <cfelseif isNumeric(value)>
                   set #colname# = #value#
<cfelse>
set #colname# = '#value#'
            </cfif>
            where eLibraryTopicID = #gridrow.eLibraryTopicID#
            
         </cfquery>
# Posted By willene | 7/8/09 10:55 AM
Hi Bruce,

Iam unable to display the cfgrid data but the form values are inserting in to database but Iam unable to bind it. So I changed it to

<cfgrid format="html" name="employeeGrid" pagesize=11
stripeRows=true stripeRowColor="gray" bind="url:employeeService.cfc?method=getData&page={cfgridpage}&pagesize={cfgridpagesize}&gridsortcolumn={cfgridsortcolumn}&gridsortdirection={cfgridsortdirection}&returnFormat=json&cfdebug"
delete="yes" selectmode="edit"
onchange="cfc:employeeService.editData({cfgridaction},{cfgridrow},{cfgridchanged})">

Its showing the error message - Error parsing JSON response:

any help would be kindly appreciated.

Thanks,
Shariff
# Posted By SHAIK MOHAMMAD SHARIFF | 8/21/10 11:28 PM
HI Bruce,
Iam able to display the records now but my new problem is Iam unable to update or delete the records it's showing an error message
_251[i] is undefined
[Break on this error] if(!_251[i].length){ in cfajax.js line 418 whenever I edit it and
_98._cf_grid is undefined
[Break on this error] var _99=_98._cf_grid.getDataSource();
whenever I delete it in cfgrid.js line 374

ANY HELP WOULD BE KINDLY APPRECIATED.

Thanks,
Shariff
# Posted By SHAIK MOHAMMAD SHARIFF | 8/22/10 11:43 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact Blog Owner