Alpha Video Training
Results 1 to 5 of 5

Thread: Sort by Logical or Numeric field works, but sort by one then the other causes error

  1. #1
    Member
    Real Name
    Al Mecklenburg
    Join Date
    Jan 2008
    Posts
    17

    Default Sort by Logical or Numeric field works, but sort by one then the other causes error

    I would like to initially sort a grid component based on first a numeric field, then by a logical field. Either sort BY THEMSELVES works fine. But trying to combine them as shown below causes an error on the page:

    Code:
    with tmpl_myGrid1
    	componentName = "myGrid1"
    	dbf.order = "Drop"	‘this is a numeric field name, the sort works fine
    	‘.dbf.order = “Priority_item”	‘this is a Logical field (CheckBox), this sort works fine also
    	‘.dbf.order = “Drop + Priority_item”	‘this sort does NOT work
    end with
    The last line results in the following error message:
    Error 4 - Invalid filter or order expression: Argument is incorrect data type
    Order expression: Drop + Priority_item



    I can sort by a Character type then a Logical type just fine as well. It seems that mixing a numeric and logical doesn't work.

    Any suggestions would be much appreciated.

  2. #2
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,609

    Default Re: Sort by Logical or Numeric field works, but sort by one then the other causes err

    Yeah, you can't combine 'em. But you can do this:

    Code:
    .dbf.order = “Drop + if(Priority_item,1, 0)”
    You may have to fiddle with the syntax a bit (I'm giving you this w/o testing, but based on experience). And depending on what you're doing, assign values other than 1 and 0.
    -Steve


  3. #3
    Member
    Real Name
    Al Mecklenburg
    Join Date
    Jan 2008
    Posts
    17

    Default Re: Sort by Logical or Numeric field works, but sort by one then the other causes err

    Thanks for your response, Steve. I tried various approaches with “IF”, as you suggest, but I couldn’t get anything to work. I’m guessing that it’s because whatever is parsing the order expression is expecting that on either side of the “+” will be a field name. The If statement (or IIF) you mentioned would return a “1” or “0” (or whatever you put in the parameters), and it doesn’t seem to me that it would be interpreted as a field name (and hence the approach won’t work).

    However, I have come up with a work-around which I present here in case it’s of use to others. This after much experimentation, and especially discovering that the “Sort Ascending/Descending” button in the dialog box where you set the choices refers to the order in which the user will see the choice offered, NOT the order in which they will be sorted on the grid (e.g., when you click the column heading). As far as I can tell, the initial sort in the grid is ALWAYS ascending.

    The workaround: 1) I made the numeric Drop field into a character field, and 2) instead of a checkbox for a field that’s defined as Logical in the associated table, I re-defined it as a character field of width 1 (in the table). Now I have two character fields (which play well together in the order expression).

    In the Grid, I assigned the field that used to be a checkbox as a DropDown Box control, and put the following in the Choices section:

    Y|Y
    |Z

    This will give the user the choice of “nothing” in the field, or “Y”. “Y|Y” means “show Y as a choice, and put Y in the field if chosen”. The “|Z” means “show nothing as a choice, but put Z in the field if chosen”.

    Apparently, when you sort that field in the grid, the sort is based on what’s STORED there (not what the user put there or SEES there). I chose Z because it’s after Y, and I wanted the Y entries to show up first in a sort.

    Hope this is helpful to others.

  4. #4
    Member
    Real Name
    Andrew Brown
    Join Date
    Nov 2007
    Location
    Twin Cities, MN
    Posts
    58

    Default Re: Sort by Logical or Numeric field works, but sort by one then the other causes err

    I've noticed that when I use the "Order" genie in a grid component it tends to convert my numeric fields to the format "str(numeric_field,19,5)". Although you've already done the type conversion yourself at the model level, that might help you in the future or maybe you can go back to your old model.

  5. #5
    Member
    Real Name
    Al Mecklenburg
    Join Date
    Jan 2008
    Posts
    17

    Default Re: Sort by Logical or Numeric field works, but sort by one then the other causes err

    Thanks, Cy. I'll give your approach a try.

Similar Threads

  1. sort or index on two numeric fields
    By Arthur Armour in forum Alpha Five Version 5
    Replies: 11
    Last Post: 03-15-2004, 10:18 PM
  2. Sort on Partial Field Value
    By WesOlfert in forum Alpha Five Version 5
    Replies: 5
    Last Post: 01-07-2004, 01:23 PM
  3. Multi field sort
    By Kyle Gateley in forum Alpha Five Version 5
    Replies: 10
    Last Post: 10-17-2003, 10:34 AM
  4. text field with numeric values - sort by
    By Jonathan Schwarz in forum Alpha Five Version 4
    Replies: 4
    Last Post: 02-28-2002, 12:28 PM
  5. Sort by Calculated Field
    By Doug Barr in forum Alpha Five Version 4
    Replies: 21
    Last Post: 08-05-2001, 10:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •