|
From: cfwild on 17 Apr 2008 12:55 Hi, I have a CFGRID that uses a cfc to bind the data to the grid. So far so good. I also have an onchange function that allows you to update the grid. I've worked up a filter in a cfselect, with a bind coming from the cfc - function is getBrandsFilter. I'm trying to get the cfselect and the cfgrid to interact, such that when a filter is picked, the grid responds. Attached is the base page and the cfc: Any thoughts on how to make this work would be greatly appreciated! cfwild Base Page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Grid Filter Test</title> </head> <body> <cfwindow initshow="true" center="true" width="485" height="520" title="Grid Filter Test"> <cfform> <cfselect bind="cfc:brands2.getBrandsFilter()" bindonload="true" name="getBrandsFilter" values="Brand" Display="Brand" STYLE="Width: 437px;" /> <cfgrid name="artists" format="html" pagesize="17" striperows="yes" selectmode="edit" bind="cfc:brands2.getBrands({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection})" onchange="cfc:brands2.editStatus({cfgridaction}, {cfgridrow}, {cfgridchanged})"> <cfgridcolumn name="UPC" display="No"/> <cfgridcolumn name="Brand" header="Brand" width="140" select="No"/> <cfgridcolumn name="Description" header="Description" width="175" select="No"/> <cfgridcolumn name="I" header="Status" width="120" values="2,1,3" valuesDisplay="Yes,No,Force"/> </cfgrid> </cfform> </cfwindow> </body> </html> cfc: <cfcomponent output="false"> <CFSET DSN = ListRest(GetAuthUser())> <CFSET TP = SESSION.tablePrefix> <CFSET THIS.dsn="#DSN#"> <!--- Get Brands ---> <cffunction name="getBrands" access="remote" returntype="struct"> <cfargument name="page" type="numeric" required="yes"> <cfargument name="pageSize" type="numeric" required="yes"> <cfargument name="gridsortcolumn" type="string" required="no" default=""> <cfargument name="gridsortdir" type="string" required="no" default=""> <!--- Local variables ---> <cfset var brands=""> <!--- Get data ---> <cfquery name="brands" datasource="#THIS.dsn#"> SELECT #TP#_quadTable.UPC, #TP#_quadTable.Brand, #TP#_quadTable.Description, #TP#_quadTable.I FROM #TP#_quadTable <cfif ARGUMENTS.gridsortcolumn NEQ "" and ARGUMENTS.gridsortdir NEQ ""> ORDER BY #ARGUMENTS.gridsortcolumn# #ARGUMENTS.gridsortdir# <cfelse> ORDER BY #TP#_quadTable.Brand </cfif> </cfquery> <!--- And return it as a grid structure ---> <cfreturn QueryConvertForGrid(brands, ARGUMENTS.page, ARGUMENTS.pageSize)> </cffunction> <!--- Get Brands Filter ---> <cffunction name="getBrandsFilter" access="remote"> <cfargument name="brand" type="string" required="no"> <!--- Local variables ---> <cfset var data=""> <!--- Get data ---> <cfquery name="data" datasource="#THIS.dsn#"> SELECT DISTINCT #TP#_quadTable.Brand FROM #TP#_quadTable; </cfquery> <!--- Add Blank Row (For No Filter) & Sort for CFSelect ---> <CFSET totalRows = (data.recordcount+1)> <CFSET getBrandsFilter = QueryNew("Brand", "VarChar")> <CFSET newRow = QueryAddRow(getBrandsFilter, totalRows)> <CFSET temp = QuerySetCell(getBrandsFilter, "Brand", " ", 1)> <CFSET counter = 2> <CFLOOP QUERY="data"> <CFSET temp = QuerySetCell(getBrandsFilter, "Brand", Brand, counter)> <CFSET counter = counter+1> </CFLOOP> <!--- Return it to CFSelect for Grid Filter ---> <CFRETURN getBrandsFilter> </cffunction> <!--- Edit Brand Status ---> <cffunction name="editStatus" access="remote"> <cfargument name="gridaction" type="string" required="yes"> <cfargument name="gridrow" type="struct" required="yes"> <cfargument name="gridchanged" type="struct" required="yes"> <!--- Local variables ---> <cfset var value=""> <!--- Process gridaction ---> <cfswitch expression="#ARGUMENTS.gridaction#"> <!--- Process updates ---> <cfcase value="U"> <!--- Get column name and value ---> <cfset colname=StructKeyList(ARGUMENTS.gridchanged)> <cfset value=ARGUMENTS.gridchanged[colname]> <!--- Perform actual update ---> <cfquery datasource="#THIS.dsn#"> UPDATE #TP#_quadTable SET #colname# = '#value#' WHERE UPC = #ARGUMENTS.gridrow.UPC# </cfquery> </cfcase> </cfswitch> </cffunction> </cfcomponent>
From: Azadi on 17 Apr 2008 13:23 update your cfgrid's bind attribute to: bind="cfc:brands2.getBrands({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection}, {getBrandsFilter(a)change}) update your getBrands method of brands2 cfc to accommodate the above change (i.e. query should have a where clause limiting the results to selected brand id) try that see how it goes - this is totally from memory, so may not be 100% accurate... Azadi Saryev Sabai-dee.com http://www.sabai-dee.com/
From: cfwild on 17 Apr 2008 15:54 Hi Azadi, Your response worked out perfectly. I'll post my changes, just in case anyone else reads this post. Thanks again! cfwild Change to the Base Page: In the cfselect: bind="cfc:brands2.getBrands({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection}, {getBrandsFilter(a)change})" Change to the cfc. Changed a line in the function: getBrandsFilter: <CFSET temp = QuerySetCell(getBrandsFilter, "Brand", "Brand Filter", 1)> **I added in "Brand Filter" instead of "". This made the next statment easier to use. Added to the function: getBrands: <cfargument name="getBrandsFilter" type="string" required="no" default=""> Also in same function added to the "brands" query: <cfif ARGUMENTS.getBrandsFilter EQ "Brand Filter"> <cfelse> WHERE #TP#_quadTable.Brand = '#ARGUMENTS.getBrandsFilter#' </cfif>
|
Pages: 1 Prev: Insure file exists before displaying Next: Another CFImage bug |