Solved

CFGRID - arrghh.. how do you use it?

Posted on 2001-06-07
8
288 Views
Last Modified: 2013-12-24
It might just be me being a novice, but i've got my grid working and updating the database fine. but when i actually use the grid i have problems.. if say i want to delete record 5, you'd think you could click on it, and it would remove record number 5, but sometimes it doesn't and it removes the LAST record instead. it's all a bit odd..

am i perhaps supposed to clik on the row header? then hit delete?

here is my code:




<cfquery name="commentsquery" datasource="commentsDB">
SELECT *

FROM comments
</cfquery>

<cfform name="GridForm" action="handle_grid.cfm">

<cfgrid name="comments_grid"
     query="commentsquery"
     Height="400"
     Width="450"
     Vspace="10"
     Insert="yes"
     Delete="yes"
     selectmode="edit"
     Sort="yes"
     Rowheaders="yes"
     Selectcolor="red">

    <cfgridcolumn name="CommentID" headerbold="yes">
    <cfgridcolumn name="Email" headerbold="yes">
    <cfgridcolumn name="FromUser" headerbold="yes">
    <cfgridcolumn name="MessText" headerbold="yes">
    <cfgridcolumn name="Posted" headerbold="yes">

  </cfgrid>

<br><input type="Submit" value="Submit">
</cfform>




==============================
action page:
======


<cfgridupdate grid="comments_grid"
  datasource="CommentsDB"
  tablename="comments">






0
Comment
Question by:M_Corkish
  • 5
  • 2
8 Comments
 
LVL 3

Expert Comment

by:SewellM
Comment Utility
You dont, at least we did not.  We ran into a multitude of problems, issues, and bugs.  We ran into browser type and version issues.  It would only display parts of the data and would show that you were at the bottom, but if you used the arrow key, more rows would mysteriously appear.  

We opted not to use it, purchased a java version, and then wrote a javascript version.  Took longer, but at least it works and we can easily modify the functionality.

Not an answer, but a heads up.  Good luck!
Michael
0
 

Expert Comment

by:MikeForbes
Comment Utility
Your on the right path!  I too have battled the CFGRID, and I kept saying to myself there has got to be a be a better way.

The only mistake I see is that on your action page, your not handling each type of possibility, but rather leaving it up to UPDATE.  Like you said, I want to delete, or add...what then.  If you are going to use CFGRID, you must become comfortable (at least somewhat) with Arrays.

The action page needs to start like this:

<!---  This sets up an array identifying what ACTION occurred for each ROW in the grid (GridTest is the sample name of the grid, use whatever your is) --->

<cfloop INDEX="Row" FROM="1" TO="#ArrayLen(Form.GridTest.RowStatus.Action[Row]#">
<!---  This loops through each row and identifies what type of action (if any) happended to it.
Then we use s SWITCH to more accurately handle each type of action --->

<!--- This sets up your switch based on the array of actions from the grid --->
<cfswitch Expression="Form.GridTest.RowStatus.Action[Row]#">
   <case value="D"> <!--- This is a predifened value for "delete" --->
      Then use CFQUERY to perform a delete of the record.
       (Your code here)
   </cfcase>
   <cfcase value="U"> <!--- Again a predifened value for "update" --->
     Then use CFQUERY to perform an update of the record.
       (Your code here)
   </cfcase>
</cfswitch>  

Just as a heads up to deal with your variables in the CFQUERY, the syntax is (for example)
    <cfquery datasource="#dsname# name="Update">
    Update employees
      set last_name = '#Form.GridTest.last_name[Row]#'
    where employee_id = #Form.Original.employee_id.[Row]#
    </cfquery>

Hope that helps,

Mike


0
 

Author Comment

by:M_Corkish
Comment Utility
Mike,
okay. i'll give your idea a try now.. 8) and let you know how i get on.

C.
0
 

Author Comment

by:M_Corkish
Comment Utility
Mike, okay what you've got makes sense, but i don't understand how to perform the update on the database.. ie:
what would i tell it to change?  which field?  as i don't know which field in a record the user wants to change?

am i missing something here?

the delete record part seems straight forward, how about the adding a new record however?

C.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Accepted Solution

by:
MikeForbes earned 50 total points
Comment Utility
M,

You would perform your Update just like you normally would (unless your dealing with numerous NUMERIC columns, in which case I can discuss later).  Now, you actually restrict what fields you want the user to be able to change (i.e. they should never be able to change a primary key field), so you just give them read-only access to those tables within the <CFGRID> tag itself.

Once you have established upfront what tables are even editable, you can set up your Update based on that.

If you are dealing with a lot of date or numeric data, then it got a little trickier for me.

I was dealing with both, so what I did was perform a validity test for each element, as you can't put an intentional NULL value in date or numeric (at least not the tables I have worked with)

(i.e. <cfif #Form.GridTest.last_name[Row]# IS NOT NULL> Then update this field, <cfelse> skip this field.)

Remember, the update is only going to occurr when the ACTION of that row matches what scenarios you have setup.
It will not just look to update any old time.

If you need more specific examples, I can help you with that, but include some of the columns your working with to help me.

Hope this helps,

Mike
0
 

Author Comment

by:M_Corkish
Comment Utility
cheers, sorry for the time taken me to get back, i've since had some other work come up.. 8(  coldfusion has had to sit aside for a few days.

anyway, okay.. i'll get on to this right away.

C.
0
 

Author Comment

by:M_Corkish
Comment Utility
Basically what i'musing this for is for my personal site, as currently if for some reason something goes wrong with uploading an image or something (it shouldn't happen!) but as a safety mechanism i'd like to go and edit the remote database. rather than download the whole file and then change it and then break it's connection, and then upload it back.

I'd ideally like to use cfgrid for my whole site. so as you'd imagine, i'd have a handfull of different fields, however, mainly just dates, text, memos etc and a few odd bits here and there.

I have created a basic content management system, to manage most of my stuff, but i thought cfgrid might be good in the interum untill that is all complete.

C.
0
 

Author Comment

by:M_Corkish
Comment Utility
thought i should close this question.. 8)

cfgrid.. grr.. 8)

i've decided to write abig content magagement system instead of just simply editing the database.

c.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
wordpress limitations 4 91
IIS Site Configuration Copy 2 67
.htacess file 301 redirects that are strange 4 42
SSL sertificate 5 48
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now