ShaBren / tkintertable

Automatically exported from code.google.com/p/tkintertable
Other
1 stars 1 forks source link

Specifiy the order of columns #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I am trying to use your module to import some stored data and programmatically 
add rows as new information comes in.  I am having trouble specifying the order 
of the columns as they are created.  

I have modified your createData() function as:

def createData():

    data = {}
    serials = [ '3456', '2343', '2345' ]
    colnames = [ 'Serial', 'IP', 'Name' ]

    for sn in serials:
        data[sn] = {}

    ips = ['172.26.2.1', '172.26.2.2', '172.26.2.3']
    names = ['Test1', 'Test2', 'Test3']

    i=0
    for sn in serials:
        data[sn][colnames[0]] = serials[i]
        data[sn][colnames[1]] = ips[i]
        data[sn][colnames[2]] = names[i]
        i+=1

    return data

The problem I am finding is that the IP column is the first column, rather than 
the serial number.  How can I switch the order of these columns at the start of 
the program?

Thanks,

Patrick

Original issue reported on code.google.com by pfarrel...@gmail.com on 3 Mar 2013 at 4:31

GoogleCodeExporter commented 9 years ago
This is not a real problem in the programm. It's rather that dictionaries have 
no fixed order. So you could rearrange the columns like that. 
yourTableModel.moveColumn(yourTableModel.getColumnIndex('columnName'), 
desiredColumnIndex)
This worked for me.
I hope I could help. :)

Original comment by LGurki...@gmail.com on 8 Jun 2013 at 1:36