Skip navigation
Currently Being Moderated

[Sorting not working] with CFGRID + Binding

Nov 2, 2010 2:23 AM

My Products.cfc is:


<cffunction name="getProducts" access="remote" returntype="any" output="yes">
        <cfargument name="page">
        <cfargument name="pageSize">
        <cfargument name="gridsortcolumn">
        <cfargument name="gridsortdirection">
        <cfif ARGUMENTS.gridsortcolumn EQ ""><cfset ARGUMENTS.gridsortcolumn = "artcod"></cfif>
        <cfif ARGUMENTS.gridsortdirection EQ ""><cfset ARGUMENTS.gridsortdirection = "ASC"></cfif>
        <cfquery name="qryProducts" datasource="#this.DSN#" result="result">
            SELECT * FROM articoli
            ORDER BY 
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.gridsortcolumn#"> 
                <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.gridsortdirection#">
        <cfreturn QueryConvertForGrid(qryProducts, page, pageSize)>


The query params work correctly, my query runs in the right way but.... the returning JSON is not sorted!

Could this be an error in the queryconvert function?


However my cfgrid doesn't work:


<cfset args = StructNew()>
<cfset = "ProductsGrid">
<cfset args.format = "html">
<cfset args.bindOnLoad = "true">
<cfset args.bind = "cfc:Products.getProducts({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
<cfset args.stripeRows = true>
<cfset args.selectColor = "##D9E8FB">
<cfset args.selectmode = "edit">
<cfset args.onchange = "cfc:Products.editProduct({cfgridaction},{cfgridrow},{cfgridchanged})"> 


    <cfgrid attributeCollection="#args#" pagesize="20">
        <cfgridcolumn name="artid" display="false">
        <cfgridcolumn name="artcod" header="xxx">
        <cfgridcolumn name="artdes" header="Descrizione" width="250">
        <cfgridcolumn name="artdesrc" header="xxx">
        <cfgridcolumn name="artcodpr" header="xxx">
        <cfgridcolumn name="artcodbar" header="xxx">
        <cfgridcolumn name="artprzacq" header="xxx">
        <cfgridcolumn name="artprzvend" header="xxx">


What am I missing?

  • Currently Being Moderated
    Mar 13, 2011 8:07 AM   in reply to fabio.bozzo

    My thinking is that it has nothing to do with cfgrid, and everything to do with cfqueryparam binding. Run the following code on a test page, and you will see what I mean:


    <cfset col = "someColumnName">
    <cfset sort = "desc">


    <cfquery name="qryProducts" datasource="yourDSN" result="result">
        SELECT * FROM articoli
        ORDER BY
            <cfqueryparam cfsqltype="cf_sql_varchar" value="#col#">
            <cfqueryparam cfsqltype="cf_sql_varchar" value="#sort#">


    <cfdump var = "#result#">


    The SQL that ColdFusion sends to the database server at compile-time is "SELECT * FROM articoli ORDER BY ? ?", plus instructions to use 'someColumnName' and 'desc' as the respective input parameters.

    Mark as:
  • Currently Being Moderated
    Mar 13, 2011 8:10 AM   in reply to BKBK

    You're right.


    CFQUERYPARAM is for parameters, not for building the SQL statement.  What the OP is trying to do is simply not valid (in any meaningful way).




    Mark as:
  • Currently Being Moderated
    Mar 19, 2011 7:17 PM   in reply to fabio.bozzo



    I've tried your version of the default cfset, but haven't had much luck in the past.  I typically use something like the following in the ORDER BY section of the SQL:


    <cfif ARGUMENTS.gridSortColumn NEQ "" AND ARGUMENTS.gridSortDir NEQ "">
      ORDER BY #ARGUMENTS.gridSortColumn# #ARGUMENTS.gridSortDir#

        ORDER BY artcod ASC


    Good Luck!



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points