De-select a CFGRID row so it can be clicked again

Apr 05, 2008

One of my colleagues recently mentioned to me that he was frustrated with CFGRID because after a grid row is selected, you can't trigger an action when it is clicked again.

 Here's the solution I found.

 First the grid code...

<cfajaxproxy bind="javascript:todetail({shipments.id})" />
<cfgrid query="sdQry" name="shipments" format="html" autowidth="false" selectonload="false" style="clear:both;">
<cfgridcolumn name="id" display="no" />
<cfgridcolumn name="INVOSHIPDATEDISPLAY" header="Pickup Date" width="75" />
<cfgridcolumn name="INVOPONBR" header="Package Nunber" width="75" />
<cfgridcolumn name="INVOBLNBR" header="BOL/Cust Ref" width="75" />
<cfgridcolumn name="CARRNAME" header="Carrier" width="150" />
<cfgridcolumn name="ORIGIN" header="Origin" width="150" />
<cfgridcolumn name="CONSIGNEE" header="Destination" width="150" />
</cfgrid>

The cfajaxproxy code sets up an event that triggers a javascript function when one of the rows is clicked on.  However, if you click on the row again, no action will occur.  This is because the shipments.id value does not change.

Here's the solution...

todetail = function(shipid) {
                    ColdFusion.navigate('shipmentdetail.cfm?action=detail&id=' + shipid,'shipmentdetails');
                    ColdFusion.objectCache['shipments'].selectedRow=-1;
}

This is the JavaScript function.  The first line is just the action that the click performs.  In this case, it loads the results of an Ajax call in a cfdiv.  The second line is what clears the selection in the grid so that it can be clicked again.  By selecting a non-existent row, we reset the id value.  The next time the row is clicked, the id changes and the javascript triggers again.

 

 

Comments

Write your comment



(it will not be displayed)





About Michael Sprague

Mike is a Web developer and manager from Central New York, specializing in ColdFusion, CSS, JavaScript, and Ajax development. More ...

Categories

Monthly Archives

Favorite Bloggers

Web Resources