Skip to main content
Aug 9, 2010 7:10 PM UTC
Question

CFGRID date sort is not working in Coldfusion 9

<!--- 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 is closed to new replies. Start a new post to keep the conversation going.

    7 replies

    Known Participant
    Sep 7, 2010 3:16 PM UTC

    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.

    Translate
    Sep 22, 2010 3:39 PM UTC

    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.

    Translate
    Feb 6, 2017 11:09 AM UTC

    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.

    Translate
    Participating Frequently
    Sep 2, 2010 8:05 PM UTC

    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 <><

    Translate
    Participating Frequently
    Sep 2, 2010 9:06 PM UTC

    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.

    Translate
    Participating Frequently
    Sep 3, 2010 12:40 PM UTC

    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 <><

    Translate