Author Topic: sorting the elements in the grid?  (Read 12552 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
sorting the elements in the grid?
« on: August 31, 2012, 09:57:07 AM »
Hi!

I am adding children to grid element by code. it seems that they are not sorted in sequence
checking/unchecking "sort" in the UIGrid gives different result but not in the sequence i have this list. i made the list public
so i can see what order elements are in the list. it seems alse that in both ways ("sort" checked or not) it does take into account
game object names that are added to the Grid element (elements beginning with "a" get displayed first...)

can i resolve this somehow, maybe using table instead of grid?

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
Re: sorting the elements in the grid?
« Reply #1 on: August 31, 2012, 10:05:03 AM »
« Last Edit: August 31, 2012, 12:28:24 PM by AndyGFX »

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: sorting the elements in the grid?
« Reply #2 on: September 04, 2012, 12:30:31 AM »
It would be extremely helpful to have the Grid (or a new component) provide a list interface (Add(), Remove(), RemoveAt(), Insert(), etc) and maintain order. I'm writing a lot of extra code to keep numbers in front of names as I add and remove items.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: sorting the elements in the grid?
« Reply #3 on: September 04, 2012, 01:01:24 AM »
Hmm... useful suggestion, thanks.

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: sorting the elements in the grid?
« Reply #4 on: September 04, 2012, 01:14:44 AM »
Thanks for that link, made for interesting reading. This was a similiar situation I was having, duplicating a list of items in code. The order was unpredictable, as was reposition. On iPhone the contents were backwards.

As a 'quick' fix I resorted to sorting them manually myself just to be sure they would work across all platforms.

Unity seems to be particularly random at sorting created items any. You only have to do a GetComponentsInChildren search on a menu object and see the order stuff is sorted in. It makes for interesting peeking.

dlewis

  • Guest
Re: sorting the elements in the grid?
« Reply #5 on: September 04, 2012, 06:55:12 AM »
I'm writing a lot of extra code to keep numbers in front of names as I add and remove items.

I'm doing the exact same thing ;)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: sorting the elements in the grid?
« Reply #6 on: September 11, 2012, 08:56:54 AM »
Hi!

So how guys you resolve this issue?
Currently i am writing numbers to maintain the order but it seems that it does not work well.
Any advice on this?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: sorting the elements in the grid?
« Reply #7 on: September 11, 2012, 10:08:47 AM »
Numbers must be in the form of 0001 0002 etc, not 1 2 3, because string comparisons think 10 is lower than 2 (but 10 would be higher than 02).

will_brett

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 40
    • View Profile
Re: sorting the elements in the grid?
« Reply #8 on: September 17, 2013, 11:42:41 AM »
I know this is an old thread, but did a solution ever get made? There are many instances that I would love to use the grid but the ordering is a problem. I would add numbers to each object in the grid, but the objects are being added throughout the game from different players over the network and the code is getting longer and more complex than it needs to be.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: sorting the elements in the grid?
« Reply #9 on: September 17, 2013, 02:40:15 PM »
I suggest just write your own grid component if you need to control the order in which objects appear, and not using UIGrid.