Link to home
Start Free TrialLog in
Avatar of M_Corkish
M_Corkish

asked on

CFGRID - arrghh.. how do you use it?

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






Avatar of SewellM
SewellM

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


Avatar of M_Corkish

ASKER

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

C.
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.
ASKER CERTIFIED SOLUTION
Avatar of MikeForbes
MikeForbes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
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.