Link to home
Start Free TrialLog in
Avatar of jfreeman2010
jfreeman2010Flag for United States of America

asked on

coldfusion cfform cfgrid column sort

Hi I have the following cfgrid and the column did NOT sort when I click and can't find out why:


<cfform method="get" format="html" id="servicelist" name="servicelist" >
      Client Name:
            <input type="text" id="namesrh" name="namesrh" >

          <cfgrid name="service_list" striperows="yes" format="html" sort="yes"
               selectonload="false"  pagesize="26" height="690"  colheaderbold="yes" selectmode=""browse"
               bind="cfc:cfc.service_list.get_servicelist({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{namesrh})"
                              onfocus="" >

          <cfgridcolumn name="ID"              width="40"       header="ID"            headeralign="left">
          <cfgridcolumn name="DATE_SERVICE"        width="75"       header="Service Date"      headeralign="left">
          <cfgridcolumn name="CLIENT_NAME"         width="210"       header="Client Name"       headeralign="left">
          <cfgridcolumn name="PROGRAM"         width="90"      header="Program"       headeralign="left">
          <cfgridcolumn name="LECTURE"          width="210"       header="Lecture"       headeralign="left">
 
           
       </cfgrid>  

   </cfform>

Thank you for helping!!
Avatar of Coast Line
Coast Line
Flag of Canada image

can u tell what error u are getting or field is disabled or what?
Avatar of jfreeman2010

ASKER

where is no error and when I click on the column hearding, it did not sort the column.
I am try to make the column sort works in this grid.
There is no error and when I click on the column hearding, it did not sort the column.

That does kinda suggest there's an error.  You need to look at the ajax logs or use some sort of javascript debugger.  Assuming it's a dev server (not production) enable ajax debugging in the cf administrator. Then display the ajax logger by appending "?cfdebug" onto the url of your grid page

             ie  http://yoursite.com/path/to/yourGridPage.cfm?cfdebug
               
You could also use Firefox's error console and/or it's Firebug plugin to check for javascript errors.
I try Firefox's error console and did not see any JavaScript errors.
I also enable ajax debugging in cf administrator and appending the cfdebug on url and not error shows. ):
Does sorting work for any grids?
Yes for other cfm pages, I used a cfstoredproc to get data, this one did not work used cfc to get data.

I try to use the same cfformand cfgrid param, but still unable to make this one works.
Well there's nothing wrong with the grid code above .. so time for a silly question - is your cfc function actually doing a sort ? ;-) Because if you're not getting any errors, that's the only thing I can think of.
Thank you for helping!!

I can sort in the cfc function, that its only the first time when display the grid.

if the grid also can sort, then when it needs, user can just click the column heading and sort it the way they want.

And yes, the cfc did sorted the data.

I did tried to comment out the order by in cfc, it did not make a diff for the column heading sort in the grid.
I can sort in the cfc function, that its only the first time when display the grid.

Do you mean sorting only works the 1st time the grid is displayed - or do you mean it never works? Also did you try with different browsers?

Any chance you can post a live URL? Because the behavior you're describing is extremely unlikely so I'm not sure what else to suggest if you've eliminated the most likely causes

1) Usually there is a javascript error OR
2) The cfc isn't really sorting the data OR
3) The data IS being sorted, but differently than you think
I used cfc to get the grid query and it works.  Are you saying what when client click on the column heading, it go back to the cfc query to do the sorting?

I am using IE 8.  I try firefox. - firefox also not working.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

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
I see my problem now.  I did not pass in the gridsortdirection.
Well you are passing it into the function.  Whether you're actually using it is a different story ;-)   But I'm very glad you figured it out.  Since you answered your own question, don't forget to select your comment as the answer and close out the thread.
I did the following, total 11 cols, 9 of then works and 2 did not. the 2 did not sort, 1 is a numeric field and 1 is chars field.

<cffunction name="get_servicelist" access="remote" ...>
        <cfargument name="page" required="true">
        <cfargument name="pageSize" required="true">
        <cfargument name="gridsortcolumn" required="true">
        <cfargument name="gridsortdirection" required="true">
        <cfargument name="namesrh" required="false">

         <cfset var qry = "">
         <cfquery name="qry " datasource="....">
                  SELECT ColumnNames, ...
                  FROM   YourTableName
               <cfif len(trim(arguments.gridsortcolumn)) gt 0>
                   ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
                </cfif>
         </cfquery>
         <cfreturn queryconvertforgrid(qry , arguments.page, arguments.pagesize) />
    </cffunction>

I got the error message:  error executing db query. [enable debugging by adding 'cfdebug' to your url parameters to see more info].
I have 2 name fileds, 1 sorted, 1 not.  other 1 is not is a id field, int.  

any suggestion on how to see the error with try to sorting those 2 cols not working?

thanks,
the cfdebug did not seem helping here.  It did pop up a error message, but did not give any value that will help.
I see the problem and will able to fix it.  thank you for help!!