Skip to main content
August 9, 2010
Question

CFGRID date sort is not working in Coldfusion 9

  • August 9, 2010
  • 2 replies
  • 2150 views

<!--- using cfgridcolum type="date" --->

<cfset emps = querynew("firstname,department, salary,startdate")>

<cfset queryaddrow(emps,3)>

<cfset querysetcell(emps,"firstname","Debra",1)>

<cfset querysetcell(emps,"department","Accounting",1)>

<cfset querysetcell(emps,"salary","100000",1)>

<cfset querysetcell(emps,"startdate","2009/11/09",1)>

<cfset querysetcell(emps,"firstname","Doherty",2)>

<cfset querysetcell(emps,"department","Finance",2)>

<cfset querysetcell(emps,"salary","120000",2)>

<cfset querysetcell(emps,"startdate","2005/09/02",2)>

<cfset querysetcell(emps,"firstname","Ben",3)>

<cfset querysetcell(emps,"department","Law",3)>

<cfset querysetcell(emps,"salary","200000",3)>

<cfset querysetcell(emps,"startdate","2010/08/09",3)>

<cfform name="form01">

    <cfgrid format="html"  insert="yes" insertButton="Add Row"

        name="grid01"

        selectmode="edit"

        width=600

        collapsible="true"

        title="Employees"

        autowidth="yes"

        query="emps"

        sort="yes"

        >

            <cfgridcolumn name="FirstName" header="FirstName"/>

            <cfgridcolumn name="Department" header="Department" />

            <cfgridcolumn name="Salary" display=true header="Salary" type="numeric" values="1000000,1200000" valuesdisplay="1000000,1200000"/>

            <cfgridcolumn name="StartDate"  display=true header="StartDate" type="date" mask="d/m/Y"/>

    </cfgrid>

</cfform>

when i sort the grid column StartDate , it is doing to text sort instead of date sort, did anybody else face the same issue?

    This topic has been closed for replies.

    2 replies

    Known Participant
    September 7, 2010

    I'm having the same problem in Coldfusion 8, so it's not just limited to 9.  Try to use the sort by clicking in the header, and it just starts sorting by months, completely disregarding year and day.

    September 22, 2010

    You can use html comment tags to put a sortable value first. i.e '<! -- 2010-12-31 -- > Dec 31, 2010'. you have to write it into your sql or use cfquerynew to do it.

    February 6, 2017

    Hi,

    I have a cfgrid populated from a database .There are two date columns.When the user sorts the dates columns they are getting sorted as though they are in string format instead of date format.

    Participating Frequently
    September 2, 2010

    I'm having the same issue.  The query is returning a field of type Date and the cfgridcolumn is set to type date but the grid sorts the data as a string.

    Mark <><

    Participating Frequently
    September 2, 2010

    It looks like CF is using the mask values to handle the sorting, if you try changing it to mask="Y/m/d" it would then sort correctly. Unfortunately it will not display to the user the way that you intended.

    Participating Frequently
    September 3, 2010

    I'm still getting the same effect.  I added a mask and the data still

    sorts as if it is a string.  Both date columns are Oracle date types.

      <cfgridcolumn name="TASKNAME" header="Type" width="200">
      <cfgridcolumn name="ORIG_StartDate" mask="Y/m/d" type="date"  header="Start Date"  width="200">
      <cfgridcolumn name="ORIG_ENDDATE" mask="Y/m/d" type="date" header="End Date" width="200">

    Mark <><