Solved

CFGRID - arrghh.. how do you use it?

Posted on 2001-06-07
8
289 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
ID: 6169300
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
ID: 6172078
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
ID: 6176407
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
ID: 6176429
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Accepted Solution

by:
MikeForbes earned 50 total points
ID: 6179299
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
ID: 6186137
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
ID: 6186160
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
ID: 6337385
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

15 Experts available now in Live!

Get 1:1 Help Now