Jump to content

GridList sorting


Drakath

Recommended Posts

What if the table has a number and a string?

myTable[1] is a string and myTable[2] is an integer.

  
table.sort(table, function(a,b) 
    return a[2] > b[2] 
end) 

I'm still not sure how to use this though. Does this override the original table.sort?

Something like this?:

table.sort(table, function(a,b) 
    return a[2] > b[2] 
end) 
  
function asdf(theTable) 
     for i, tableValue in ipairs(theTable) do 
     local row = guiGridListAddRow(theList) 
      table.sort(tableValue) 
      guiGridListSetItemText ( theList, row, Column2, tableValue[2], false, true ) 
 end 
end 

Link to comment
What if the table has a number and a string?

myTable[1] is a string and myTable[2] is an integer.

  
table.sort(table, function(a,b) 
    return a[2] > b[2] 
end) 

I'm still not sure how to use this though. Does this override the original table.sort?

Something like this?:

table.sort(table, function(a,b) 
    return a[2] > b[2] 
end) 
  
function asdf(theTable) 
     for i, tableValue in ipairs(theTable) do 
     local row = guiGridListAddRow(theList) 
      table.sort(tableValue) 
      guiGridListSetItemText ( theList, row, Column2, tableValue[2], false, true ) 
 end 
end 

No, you have to use table.sort in the table (in your example called theTable) before using for loop, see:

function asdf(theTable) 
    table.sort(theTable, function(a,b) return a[2] > b[2] end) 
    for i, tableValue in ipairs(theTable) do 
        local row = guiGridListAddRow(theList) 
        table.sort(tableValue) 
        guiGridListSetItemText ( theList, row, Column2, tableValue[2], false, true ) 
    end 
end 

Link to comment

There is another problem in this case. theTable is a table that stores more tables. The numbers I need to sort are tableValue[2]. I can't sort theTable because it would try to compare two tables.

Should I try to make another table which would store every tableValue[2] and then sort it or is there a better way?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...