Skip to main content
April 28, 2010
Question

Sorting Query Columns

  • April 28, 2010
  • 3 replies
  • 491 views

Hello,

I am having issue.

When create a query, this query  columns are sorted alphabetically. For example:

TestQuery = QueryNew("Date, Text, ID").

Probably not, but the dump shows: | Date | ID | Text |.

In my Flex application in the DataGrid, too.

How I can sort the Query columns that they remained in an order in which have been added in new Query?

Sorry for my English

    This topic has been closed for replies.

    3 replies

    Inspiring
    April 29, 2010

    it depends how you reference the colums.  The variable CF provides, queryName.columnList is sorted alphabetically (I have no idea why: CF trying to be "helpful", I guess.  Not really very helpful).  <cfdump> uses this variable to display the columns, hence the columns being sorted alphabetically.  However <cfdump> is just a debugging tool, so that doesn't matter.

    If you do getMetadata() on a query, it returns the columns in an array which preserves the original order of the columns.  I have no idea what Flex does to decide what order to present the columns in (I have never used Flex).  I would have thought that would be down to the developer (ie: you)..?

    --

    Adam

    April 29, 2010

    I was mistaken. The data is stored as it is required(I have looked in  a debugger). But, in a Flex DataGrid they are sorted in alphabetic  order...

    Then I will pass a variable with columns in a flex. It will solve  a issue, but the decision seemed to me that is easier.

    Thanks  Dan, Adam!

    April 29, 2010

    Sorry, I have not understood.

    It is necessary to make so?

    columns = "Date, Text, ID";
    TestQuery = queryNew(columns);

    Or do you speak about other way?

    Inspiring
    April 29, 2010

    You have the right idea.  I do that very thing quite often for a variety of reasons.  It gives you more control than using the columnlist variable that cfquery provides.  I don't use flex, so I don't know how much flexibilty one would have with grids.

    Inspiring
    April 28, 2010

    Make them a variable.