APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form
When you need to update values which were returned from a database table or set some specific formatting before sending data to the client side, you should use the beforeRender event handler.
<cfinclude template="../config.cfm">
<cffunction name="color_rows">
<cfargument name="row">
<cfif ARGUMENTS.row.get_index() mod 2>
<cfset ARGUMENTS.row.set_row_color("red")>
</cfif>
</cffunction>
<cfset grid = CreateObject(
"component",
"dhtmlxConnectors.GridConnector").init("#datasource#","MySQL")>
<cfset grid.event.attach("beforeRender",color_rows)>
<cfset grid.render_table("grid50000","item_id","item_nm,item_cd")>
APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form
<!--- render field as details link --->
<cffunction name="formatting">
<cfargument name="row">
<cfset var data = ARGUMENTS.row.get_value("some_field")>
<cfset ARGUMENTS.row.set_value(
"some_field",
"<a href='details.cfm?id=#data#'>Details</a>"
)>
<!--- formatting date field --->
<cfset data = ARGUMENTS.row.get_value("other_field")>
<cfset ARGUMENTS.row.set_value(
"other_field",
DateFormat(lsParseDateTime(data),
"mm-dd-yyyy")
)>
</cffunction>
<cfset grid = CreateObject(
"component",
"dhtmlxConnectors.GridConnector").init("#datasource#","MySQL"
)>
<cfset grid.event.attach("beforeRender",formatting)>
APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form
More complex formatting rules can be defined by using extra fields during the configuration.
<cffunction name="formatting">
<cfargument name="row">
<!--- set row color --->
<cfset ARGUMENTS.row.set_row_color(ARGUMENTS.row.get_value("color"))>
<!--- save in userdata --->
<cfset ARGUMENTS.row.set_userdata("some_data",ARGUMENTS.row.get_value("count"))>
</cffunction>
<cfset grid = CreateObject(
"component",
"dhtmlxConnectors.GridConnector").init("#datasource#","MySQL"
)>
<cfset grid.event.attach("beforeRender",formatting)>
<cfset grid.render_table("some_table","id","name,price","color,count")>
APPLICABLE TO: Tree, TreeGrid
TreeGrid provides TreeGridDataItem and Tree provides TreeDataItem as the input parameter of the beforeRender event handler. Both of them support base operations and a few specific ones.
<cffunction name="custom_format">
<cfargument name="item">
<cfif ARGUMENTS.item.get_value("complete") gt 75>
<cfset ARGUMENTS.item.set_check_state(1)>
</cfif>
<cfif ARGUMENTS.item.get_value("duration") gt 10>
<cfset ARGUMENTS.item.set_image("true.gif")>
<cfelse>
<cfset ARGUMENTS.item.set_image("false.gif")>
</cfif>
</cffunction>
<cfset tree.event.attach("beforeRender",custom_format)>