Jump to content

Sorting a gridlist?


tim260

Recommended Posts

Hello fellow MTA'ers,

I am having the following problem. I have had a spawn menu for ages now and this problem has been bothering me for some time. I have a grid list called Spawn. And an XML file where its loaded from. the XML looks like this

< just an example >

  
<city name="North"> 
    <class name="Admin" r="200" g="200" b="200"> 
        <spawn name="Admin 1"  all the info... > 
            <skin>217</skin> 
        </spawn> 
                <spawn name="Admin 2"  all the info... > 
            <skin>217</skin> 
        </spawn> 
                <spawn name="Admin 3"  all the info... > 
            <skin>217</skin> 
        </spawn> 
    </class> 
</city> 
  

Instead of outputting the Grid like this

- Admin 1

- Admin 2

- Admin 3

it outputs it like:

- Admin 1

- Admin 3

- Admin 2

How is this possible? the script wich creates te list is below.

  
function onClassClick(button) 
    if source == classGridList and button == "left" then 
        if guiGridListGetSelectedCount(cityGridList) > 0 and guiGridListGetSelectedCount(classGridList) > 0 then 
            guiGridListClear(spawnGridList) 
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( cityGridList );  
            local cityName = guiGridListGetItemText( cityGridList, selectedRow, selectedCol )  
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( classGridList ); 
            local className = guiGridListGetItemText( classGridList, selectedRow, selectedCol ) 
  
            local classSkins = cities[cityName][className] 
            for x, y in pairs(classSkins) do 
                local row = guiGridListAddRow(spawnGridList) 
  
                guiGridListSetItemText(spawnGridList, row, 1, x, false, false) 
            end 
            guiSetProperty(spawnScreenOKButton, "Disabled", "True") 
            guiSetProperty(skinPrevButton, "Disabled", "True") 
            guiSetProperty(skinNextButton, "Disabled", "True") 
            guiSetText(skinNumberLabel, 1) 
            unRenderSkin() 
        end 
    end 
end 
  
  

Link to comment

Make the table an index table and then sort it before you populate the grid list. You can also use table.insert function to insert each class to the table in the same order it was loaded from the xml file. Once you have an index table iterate it with ipairs instead of pairs, this way the order will always be the same since pairs does not always iterate in the same order.

Link to comment
Make the table an index table and then sort it before you populate the grid list. You can also use table.insert function to insert each class to the table in the same order it was loaded from the xml file. Once you have an index table iterate it with ipairs instead of pairs, this way the order will always be the same since pairs does not always iterate in the same order.
Sorry i dont work with those index and table stuff alot could you give me a brief example, much aprreciated.
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...