Hi,
I must be making a silly mistake regarding scope, but i am battling with this simple 3 column sort. Can anyone please help in updating my sorted data.
Thank You..
# 3 col list sorting
import ui
from operator import itemgetter
sdata = [('Bob','Dylan',58),('Eric','Clapton', 56),('Elvis','Presley',48),('Michael', 'Jackson', 60),('Al', 'Stewart',54),('Boz', 'Scaggs',64)]
ditemsa = []
ditemsb = []
ditemsc = []
for x in range(len(sdata)):
ditemsa.append(sdata[x][0])
ditemsb.append(sdata[x][1])
ditemsc.append(sdata[x][2])
def sortaction(self, opt=0):
global sdata
sdata = sorted(sdata,key=itemgetter(opt))
ditemsa = []
ditemsb = []
ditemsc = []
for x in range(len(sdata)):
ditemsa.append(sdata[x][0])
ditemsb.append(sdata[x][1])
ditemsc.append(sdata[x][2])
print(sdata)
####
# how toupdate data_source display
# after pressing sort
####
tbv1.data_source.items=ditemsa
tbv2.data_source.items=ditemsb
tbv3.data_source.items=ditemsc
def bt1_action(self):
sortaction(self, 0)
def bt2_action(self):
sortaction(self,1)
def bt3_action(self):
sortaction(self,2)
class MyView(ui.View):
def __init__(self, name='MyView', bg_color='lightyellow', frame=(0,0,360,660)):
self.name = name
self.bg_color = bg_color
self.add_subview(self.make_table_view('tbv1', (0, 50, 100,600), 'green',ditemsa))
self.add_subview(self.make_table_view('tbv2', (105, 50, 100,600), 'blue', ditemsb))
self.add_subview(self.make_table_view('tbv3', (210, 50, 100,600), 'red',ditemsc))
self.add_subview(self.make_btn_view('bt1','FName', (0,0, 100,40),'palegreen', action=bt1_action))
self.add_subview(self.make_btn_view('bt2','LName', (105,0, 100,40),'skyblue', action=bt2_action))
self.add_subview(self.make_btn_view('bt3','Age', (210,0, 100,40),'pink', action=bt3_action))
self.present()
def make_table_view(self, name, frame, col, dsrc):
table_view = ui.TableView(name=name, frame=frame)
table_view.row_height = 25
data_source = ui.ListDataSource(dsrc)
data_source.name = dsrc
data_source.text_color=col
data_source.font=('Avenir Next Condensed',14)
table_view.data_source = data_source
return table_view
def make_btn_view(self, name, title, frame, col, action):
btn_view = ui.Button(name=name, frame=frame, bg_color=col)
btn_view.title=title
btn_view.tint_color=0
btn_view.action = action
return btn_view
MyView()