Solved

CFGRID - arrghh.. how do you use it?

Posted on 2001-06-07
8
293 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion Datefield problem 2 124
Website being blocked? 3 136
UPLOAD FILE TO Web API USING POST 5 132
Intranet and Kerberos Authentication (not sharepoint!) 8 152
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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