Announcement

Collapse
No announcement yet.

Control Sorting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shrek
    replied
    Hi, thanks, well never mind about the % because I forgot I had the raw data to make the % so I just sorted that instead.

    Leave a comment:


  • reteset
    replied
    Shrek

    I could not understand what did you mean by percentage
    If you could elaborate a bit more then i would help on that as well

    Please show an example of data that you want to be sorted

    Leave a comment:


  • Shrek
    replied
    @reteset, this is pretty good, do you think you could add % to the options? say at most 2 decimal places but on whole %'s no decimal.

    Leave a comment:


  • aboad
    replied
    thanks reteset :yes

    Leave a comment:


  • Shrek
    replied
    Cheers, just finished moving home and haven't ported it over yet but I will be back with an example of what I'm trying to achieve

    Leave a comment:


  • reteset
    replied
    Originally posted by Shrek View Post
    Cheers mate, sent you the donation but you have the note field turned off so couldn't link to this.

    I shall port your code to a sample and check it out, should have made the sample first really :yes
    Hi ,sorry for late reply and thanks for donation :yes

    I created that donation link in 2006 or 2007 and did not know what i am doing at the moment :o

    I can make modifications on the sort function according your project requirements upon your request

    Thanks

    Leave a comment:


  • Shrek
    replied
    Cheers mate, sent you the donation but you have the note field turned off so couldn't link to this.

    I shall port your code to a sample and check it out, should have made the sample first really :yes

    Leave a comment:


  • reteset
    replied
    Hi Shrek

    When we look at the your table structure , you have used 0 as the starting index of that table
    even if there is no problem with that , you know that Lua tables (numerically indexed) are 1 based
    in order to implement a proper table iteration (if it will be sorted then) you should use 1 based index

    if your custom control is 0 based then you can easily convert index/ID by using a +1 or -1 on the value

    simply when you want to access this table by the item index of your custom control ,use +1 on that index to access table

    for example you selected first item in your control , and its index is 0
    when you want to access associated data on your lua table

    Items[ItemSel+1]

    this is a shortcut to your MapIDtoIndex() and MapIndexToID() functions

    i would explain more if i could have some more info about your control

    i created a detailed example ,that sorts COL1 as string ,COL2 as number
    and COL3 as file size ,it also compares file size against KB ,MB ,GB etc..

    you only need to align index to/from table , something like below

    Code:
    for i = 0 ,#Items do
       DrawItem(Items[i+1].COL1,Items[i+1].COL2,Items[i+1].COL3)
    end
    and when you add an item to your control which will return a zero based index
    just use table.insert() that will automatically assign an index to associated data

    in addition to these , sort algorithm does not change index , only its value
    this will also avoid that index confusion

    here is the sample project :
    Attached Files

    Leave a comment:


  • Shrek
    started a topic Control Sorting

    Control Sorting

    I have a table like so:

    Code:
     Items = {}
     Items[0]={COL1="Apples",COL2=1.77,COL3="1.1 MB"}
     Items[1]={COL1="Oranges",COL2=1.8,COL3="56.8 GB"} 
     Items[2]={COL1="Bananas",COL2=3,COL3="19 B"} 
     Items[3]={COL1="Pears",COL2=7,COL3="44 MB"}
     Items[4]={COL1="Grapes",COL2=2.5,COL3="77 KB"}
    The table index is the ID of the item as well as the initial index.
    I want to sort the table ascending or descending for alphabetic and numeric.
    When the user selects the item the variable 'ItemSel' is set to the current index.
    The control is redrawn every half a millisecond or on interaction (sorting/selecting) and it is darw by what is in the 'Items' table.
    I need some help with the following functions:

    Code:
     function SortAlphaAss()
     
     end
     function SortAlphaDec()
     
     end
     function SortNumAss()
     
     end
     function SortNumDec()
     
     end
     function MapIDtoIndex()
     
     end
     function MapIndexToID()
     
     end
    I'm open to changing the method if its easier to code but the end result needs to be a functioning table sort that maps the ID to the index so that on redraw the control sorts the relevant column.

    There is a £20 (UK sterling) PayPay payment to anyone that can do this.
Working...
X