Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CFGRID - arrghh.. how do you use it?

Posted on 2001-06-07
8
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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
 

Accepted Solution

by:
MikeForbes earned 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

705 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