New call-to-action
Results 1 to 9 of 9

Thread: Grouping a Grid

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

    Default Grouping a Grid

    Without building some custom code, I can't think of a way to group a grid. Any suggestions?

    For instance, each record has a category and a name, but I only want the category to show up once:

    Code:
    Apple
      Delicious
      Granny Smith
      Yellow
    Grapefruit
      Orange
      Pink
    -Steve


  2. #2
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,656

    Default Re: Grouping a Grid

    Since a grid displays records, and "Apple" & "Delicious" are in the same record, I doubt you can put them on separate lines - unless you had a dummy record w. "Apple" first - etc. etc.

    The only thing I can think of is use xbasic to mark a .L. field called "Cat", which only marks the first instance of "apple", etc. Then put a calc field in the grid:

    If(Cat=.T., Category, Name)

    Same principle as a browse, I think. Unless there is a way to get the previous() function to fire in a grid (but I doubt it).

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

    Default Re: Grouping a Grid

    Yeah, I'm thinking about trying to invent a calculated field too. I don't even mind if the first group label is to the side of record entry with the rest of the group name instances hidden. I might even be able to fix that with a bit of html in the calc field...
    -Steve


  4. #4
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,656

    Default Re: Grouping a Grid

    Maybe it should be something like:

    If(Cat=.T., Category + ": " + Name, space(10)+Name)

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

    Default Re: Grouping a Grid

    OK, it can be done with use of an index, calc field in the grid and a couple other touches. Too complicated to spend the time 'splaining here unless someone else needs it. For proof, see attached pic.
    -Steve


  6. #6
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,849

    Default Re: Grouping a Grid

    THANKS! I was just in need of this for a list of Events by Category.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

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

    Default Re: Grouping a Grid

    I presume this means you want an explanation....?
    -Steve


  8. #8
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,849

    Default Re: Grouping a Grid

    You know I couldn't live with myself if you did!
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

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

    Default Re: Grouping a Grid

    Allright, let me try to be as clear and precise as possible. I'm going to use my example so I don't have to interpret -- I'll leave that to you. And, it might be a good idea to review my uploaded picture below to keep in mind the desired result.

    My key fields here are:

    vendor->category
    vendor->name_full

    I want to group vendor names by category.

    First, an index named "Category" with this expression:

    Code:
    UT(FOOD_CATEGORY) + UT(NAME_FULL)
    Next, a calc field in the grid, which is based on the vendor.dbf:

    Code:
    vCategory = if(ut(Name_Full)=lookupc("c",ut(Food_Category),"ut(name_full)","[pathalias.adb_path]\vendor.dbf","category"),ut(food_category),"")
    The lookupc() function is used here, using the "c" for "closest" as the first parameter of the function. Because the key is incomplete, e.g. I'm just using the record's Food_Category field rather than the complete expression in the index, it finds just the closest match, which -- this is important: -- also happens to be the first match. Using Lookupc("f", ....) won't work. That means that, since each category is indexed alphabetically by Name_Full, the only time that the vCategory expression is true and returning the ut(food_category) is when it's the first Name_Full with that category. Reread this part until you understand it because it's the key to making this happen.

    Now, put vCategory into your Selected grid fields as a Label, and hide the column. Make the Name_Full field a Freeform layout with something along these lines:

    Code:
    <table>
    <tr valign="top"><td width="190" align="center" valign="top">{Vcategory}{name_full}</td>
    </tr>
    </table>
    I made the cell width too narrow to hold both controls in order to force a wrap. I still have a bit of a vertical spacing problem between rows to handle, but overall I'm satisified with the result.

    Lemme know if I failed to make anything clear enough here. And show us your results!
    -Steve


Similar Threads

  1. Grouping within reports
    By Robert Bowman in forum Alpha Five Version 5
    Replies: 3
    Last Post: 08-26-2003, 02:50 PM
  2. Grouping??????
    By BRIAN GRAY in forum Alpha Five Version 5
    Replies: 1
    Last Post: 07-09-2003, 01:22 PM
  3. Grouping problems
    By dhusk1113 in forum Alpha Five Version 5
    Replies: 8
    Last Post: 06-30-2003, 04:36 AM
  4. GROUPING NAMES TOGETHER
    By Janet Seber in forum Alpha Five Version 5
    Replies: 9
    Last Post: 05-29-2003, 08:04 AM
  5. Report Grouping
    By GregOnline in forum Alpha Five Version 4
    Replies: 5
    Last Post: 02-01-2002, 10:17 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
  •