Question

Coldfusion (cfgrid) grid multiple update/insert with dropdown (combo) boxes - a bit technical, and definitely worth 500 pts

Asked by: vitoasaro

I'm using Coldfusion MX 7, and I've seen that ColdFusion can now bind many form elements to a CFgrid.

Can someone please tell me how to do the following:

I need to build a grid with data from a SQL query which will consist of 3-4 columns. Each column should consist of a drop-down box (single select combo box, not multi), populated with all the useable values, one of which will be selected based on the data from the query (a stored procedure will provide this data).

I also need to be able to dynamically add multiple rows to the grid with combo boxes.  In other words, if the user clicks "add row," I want to increase the grid by another row without doing a submit and refresh to the grid, therefore, I'd like to be able to add more than a single row, then process all of the rows at once when a "submit" is finally requested.

I also need to be able to delete any checked rows (bind a checkbox in a column) to a piece of data, and not have the grid update/refresh each time a row is deleted; again, it needs to wait until final processing.

So, when the user finally clicks "update" or "process" or whatever we call it, the subsequent page will go through all of the rows on the grid, and simply recreate the record with all the new edits, leaving out anything that was selected for deletion, and including all of the new rows (with their combo box values) which had been added to the bottom of the grid.

I know this may sound a bit complicated, especially with binding the different form types into the grid (combo box, check box) which why I've given this 500 points.  I'm in a bit of a hurry and need to get this going within two weeks.  Thanks!



This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-08-09 at 12:27:07ID21948949
Tags

cfgrid

,

coldfusion

,

update

Topics

ColdFusion Application Server

,

ColdFusion Studio

Participating Experts
1
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CFGRID
    When I use CFGRID, I have 10 columns so I need to be able to scroll horizontally. The vertical bar shows up if needed but not the horizontal one. Any thoughts
  2. Select in CFGRID
    Can we use CFSelect (database driven) in CFGRID.
  3. CFGrid
    Hi, I'm using cfGrid to display my selecting data from database. But the data can't display out in ie 5.5 and NetScape 4.7 and above. Following are the error message. IE 5.5 Error Message: load: class allaire.controls.cfGridFormApplet not found NS 4.7 Applet allaire.contr...
  4. CFGRID
    I have a page where I use CFGRID to display the results. I need to validate that the filed type is always "slide". I have tried using the ONVALIDATE but cannot get the javascript correct. Does anybody know how to do this? The code is as follows: <cfform name=&qu...
  5. CFGRID
    Is it possible to use data from one table to populate a CFGRID, but then update/insert into a different a different table using CFUPDATEGRID? I need to insert the records into a temporary table. If it's possible, then I am not sure what the problem is. I am using Access20...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: gdemariaPosted on 2006-08-10 at 06:31:49ID: 17287447



Is each row of the grid a record in the datatbase; and the columns are fields in that row?

Like this?

MyTable
  Col1  
  Col2
  Col2

Record 1:            Col1               Col2            Col3
Record 2:            Col1               Col2            Col3
Record 3:            Col1               Col2            Col3
           

> I also need to be able to dynamically add multiple rows to the grid with combo boxes.  In other words, if the user clicks "add row," I want to >increase the grid by another row without doing a submit and refresh to the grid, therefore, I'd like to be able to add more than a single row, then >process all of the rows at once when a "submit" is finally requested.

Is it Ok to submit without saving?  Just refresh the page with the additional row? (perserving all data entered of course)
If it is, I will guide you on that using CF
If not, you should post this part in the Javascript area, it can be done through javascript by writing a new block containing the HTML for the row.

>I also need to be able to delete any checked rows (bind a checkbox in a column) to a piece of data, and not have the grid update/refresh each
>time a row is deleted; again, it needs to wait until final processing.

Would it work to check a box at the start of the row that says "delete" but not have the row change or hide?   When submitted, the row would  be deleted, until then it just shows a checkbox flagged for deletion?

 

by: vitoasaroPosted on 2006-08-10 at 09:25:50ID: 17289080

Yes, almost exactly like your seond example... Each row is a record in a sense.

Primary Record:
Record 1:            Col1               Col2            Col3
Record 2:            Col1               Col2            Col3
Record 3:            Col1               Col2            Col3

The data contained in Col1, Col2, & Col3 are each their own respective "drop down box" (single-select combo box).  I've added the primary record (let's call it "merchant" to keep things organized).  The "merchant" record in the database will be linked (one to many) to the other records in another table.  For example, if I select "merchant" ID=1 (where merchantID=1), let's say I receive three records back from its linked table (as you've shown above).  Each record has three pieces of data, columns 1-3 (let's call them C1, C2, and C3 to make it easier). In the merchant query C1 may equal 0 (nothing selected, or "default" selection of the combo box), or another integer.  A separate cf_stored_procedure (query) is called which populates each and every dropdown (C1-C3) with the same categories & their own ID #'s so that if C1, C2, or C3 is greater than 0, it will match one of the category ID #'s.  A higher numbered category box should not be "selectable" unless it's preceeding lower number box has something selected from it, i.e., you can't choose something from C2 unless something in C1 has been selected, and you can't choose something from C3 unless C2 has been selected.

>Is it Ok to submit without saving?  Just refresh the page with the additional row? (perserving all data entered of course)
Absolutely.  This is sort of the direction I was thinking it might need to go to be able to keep adding extra rows and "grow" the table before submitting the data.

>Would it work to check a box at the start of the row that says "delete" but not have the row change or hide?   When submitted, the row would  be deleted, until then it just shows a checkbox flagged for deletion?
Yes, right on the money.  This is the functionality I was referring to originally.  The row is simply checked with a checkbox as a flag to be deleted when the data is submitted for processing, but does not need to immediately be removed or hidden. In fact, it shouldn't be immediately removed or hidden in case the user changes their mind and decides not to delete that row.  When the all of the data is submitted to be processed, the rows that were checked should simply be "overlooked" and left out of the processing.  All of the other rows, however, need to be analyzed to update changes to any dropdown.  The way the current stored procedure will operate is that it will "overwrite" the Primary Record with the entire contents of the grid, i.e., new rows + changes to existing rows, leaving out deletes.

Here's an example of a dataset (grid):

Primary Record (merchant ID=1):
merchant_id     |     Category1     |     Category 2     |     Category 3     |     Delete?     |
        1                          0                        0                           0
        1                          1                        0                           0
        1                          2                        5                           0
        1                          2                        6                           0
        1                          3                        1                           0                       X
        1                          3                        1                           2
        1                          3                        1                           3                       X
->     1                          3                        1                           5   (new row)
->     1                          3                        2                           1   (new row)

The new rows have been added "on the fly" and should be part of the entire dataset, while the two rows that have been checked for deletion (shown with X's) should be "skipped" when looping through the dataset to create the new record.  Hope this helps!

Thanks again!

 

by: gdemariaPosted on 2006-08-11 at 07:23:54ID: 17296319


ok, good.

Part one..  Populate form fields from the database query..

<cfquery name="getData"
   select * form table...
</cfquery>


<cfoutput Query="getData">
   <cfloop index="aCol" list="ID,category1,category2,category3">  ---- list all to be included

       <cfset "form.#aCol#_#getData.currentRow#" = getData[aCol][getData.currrentRow]>

   ... the result if form variables in this format...

    form.ID_1,  form.category1_1
    form.ID_2,  form.category1_2

Now add a few blank ones on at the end...

<cfset variables.Number_of_Empty_Records = 3>
<cfset variables.Total_records = getData.recordCount + variables.number_of_empty_records>

<cfloop index="jj" from="#getData.recordCount# + 1" to="#variables.total_records#">

   <cfloop index="aCol" list="ID,category1,category2,category3">  ---- list all to be included

       <cfset "form.#aCol#_#jj#" = "">

 
this will create more

Part two..  Creating the form fields.  

<cfloop index="kk" from=1 to="#variables.Total_records#">

 <input type="hidden" name="ID_#kk#"  value="#form['ID_#kk#']#">   --- be sure to include the primary key of the table

 <select name="catgory1_#kk#">         ---- do your select tags, make sure to select the correct option
     place your loop here for your values, test if the option is SELECTED with
         <cfif form['category1_#kk#'] is  (value of category1 in loop)> selected </cfif>

 <input type="checkbox" name="deleteMe_#kk#" value="Y">   ---- add a checkbox for delete, if checked, you will delete later..

</cfloop>

<input type=Hidden name="total_records" value=#variables.total_records#">  ----  include in your form submit # of  records


step three... loop through and update / insert / delete your data

<cfloop index="kk" from="1" to="#variables.total_records#">

   <cfset variables.ID = form['ID_#kk#']>  
   <cfif IsDefined("form.deleteMe_#kk#")>
       <cfif variables.ID is not ""> .... if no ID and delete checked, its a new record they decided to delete, do nothing
        .... place delete here
       </cfif>
   <cfelse>

      <cfset variables.category1 = form['category1_#kk#']>  
      <cfset variables.category2 = form['category2_#kk#']>  
      etc...

    <cfif  variables.ID is NOT ""> ---- has an ID, update the record

        ... place update statement here
   <cfelseif (SOME CRITERIA, SEE COMMENT BELOW*)>

       ... place insert statement here
   </cfif>

</cfloop>


* if the user requested an additional record, but never filled it in and clicked submit, you don't want to try and save data that is not complete, and you may not want him to have to check the delete box on an empty record.   So perhaps come up with some required minium entries that if not make you ignore the record (ie.  its a blank record that stayed blank, do not insert).



Obviously the code is all rough to give you the concepts, hopefully you can work out exact syntax with your specific code.
Let me know how it goes,
Gary

 

by: gdemariaPosted on 2006-08-11 at 07:46:42ID: 17296527


 oops, I left handling the form submits...


Part one should be enclosed in a <CFIF statement.  
You only want to take the variables from the database if the form was NOT submitted (frist time on page)
Every form submit, you will just let the page repopulate with the submitted form values


<cfif  (test if form submitted for SAVE) >   --- The form WAS submitted with the SAVE action, so SAVE data..
  <cftry>
      -- do step 3 here --
      loop to insert, update, delete records

     <cflocation url="thankyou.cfm"> ---- done, go to next page

     <cfcatch type="any">
        <cfset variables.error = "#cfcatch.message#">
     </cfcatch>
  </cftry>
</cfif>


<cfif NOT IsDefined('form.submit')>  ---- the form was NOT submitted

   ... its the first time on page, populate form fields from query

   -- do step 1 here --
   <cfquery name="getData">
   ... populate the form fields

</cfif>

<cfif  (add record request)>   ---- form submitted with request to add a record

  <cfset variables.Last_Value = variables.total_records>
  <cfset variables.total_records = variables.total_records + 1> ---- number to add, just 1?

  <cfloop index="jj" from="#variables.Last_Value# + 1" to="#variables.total_records#">
     <cfloop index="aCol" list="ID,category1,category2,category3">  
          <cfset "form.#aCol#_#jj#" = "">
     </cfloop>
  </cfloop>

</cfif>

 

by: vitoasaroPosted on 2006-08-14 at 21:19:42ID: 17315515

Thank you so much, gdemaria.

I see in the pseudo-code there is a spot where a few blank rows are added, but I was wondering if there's a way to have the rows dynamically added by the user clicking a "new record" button of some sort.  In the program above it appears that 3 empty ("new slots") rows are created when the screen is first created, but is there a way using cfgrid and binding the combo-boxes into the grid to do this (and the rest, of course)?

Thank you!

 

by: gdemariaPosted on 2006-08-14 at 21:48:23ID: 17315610



You can DROP this part out of step One in my first comment
----------------------------------------------------------------------------
Now add a few blank ones on at the end...

<cfset variables.Number_of_Empty_Records = 3>
<cfset variables.Total_records = getData.recordCount + variables.number_of_empty_records>

<cfloop index="jj" from="#getData.recordCount# + 1" to="#variables.total_records#">

   <cfloop index="aCol" list="ID,category1,category2,category3">  ---- list all to be included

       <cfset "form.#aCol#_#jj#" = "">

----------------------------------------------------------------------------
Yes, the above will add a few blank lines at the end, if you don't want that, no problem.  Just remove the code.
Or you can change the variable   Number_of_Empty_Records = 0



Now, look at the last section of my 2nd comments....
------------------------------------------------------------------------------------------------------------------
<cfif  (add record request)>   ---- form submitted with request to add a record

  <cfset variables.Last_Value = variables.total_records>
  <cfset variables.total_records = variables.total_records + 1> ---- number to add, just 1?

  <cfloop index="jj" from="#variables.Last_Value# + 1" to="#variables.total_records#">
     <cfloop index="aCol" list="ID,category1,category2,category3">  
          <cfset "form.#aCol#_#jj#" = "">
     </cfloop>
  </cfloop>

</cfif>
------------------------------------------------------------------------------------------------------------------

The above code, will increment the "total_records" by one.  And create your empty form fields.
All you need to do is create a button "Add Record" that will submit the form to itself and go inside that
CFIF condition.   The extra row will be created.

The form fields will not lose their value, but we are only working with FORM scope variables and we do not
pull from the database again after the first page view.   That is, we do Not write over the form fields
when the user clicks to add the blank record, so all values entered will be there.


I have not used the cfgrid, but there is a flash version and the older java version I believe.   The flash one works well,
it's just a completely different animal to show the user from the rest of your forms.

Best,
Gary


 

by: vitoasaroPosted on 2006-09-16 at 18:27:55ID: 17536884

Gary,

It looks like that will do the trick.  I really would like to use the new Flash 8 bind feature to bind the different form types (combo box) to the coldfusion grid type=flash component, but that appears as if it will be a much more of a complicated solution, though more of what I'm trying to achieve.  However, yours appears to be a great interim work-around for me.  Thanks again!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...