Okay, I've done it like that, just wait for the next revision
EDIT:.
btw, example TableView code for the tableView.
Create data object and put it into create TableView statement. the data object really only needs the functions, and 'self' is the tableView, not the data object itself. I've sourced my data from arrays but you can do it from anywhere else.
Looks like this for now:
Code: Select all
--TABLEVIEW
local tData={};
tData.cells={}; --used to cache cells
tData.headers={{"IP Address", 100}, {"Game Type", 100}, {"# Players", 100}}; -- column info, col name and col width
tData.mpgames={ --table data
{"192.168.0.2", "Melee", "2"},
{"192.168.0.5", "Death Match", "5"},
{"192.168.0.13", "Custom", "8"},
{"192.168.0.7", "Default", "3"},
{"192.168.0.9", "Melee", "2"},
{"192.168.0.3", "Default", "8"},
{"192.168.0.8", "Death Match", "4"}
}
function tData:attributesForColumn(columnIndex)
return unpack(tData.headers[columnIndex]); --return headerName, columnWidth
end
function tData:viewForCell(rowIndex, columnIndex)
--tableview queries a view at row, column
tData.cells[rowIndex]=tData.cells[rowIndex] or {};
tData.cells[rowIndex][columnIndex]=tData.cells[rowIndex][columnIndex] or
LoveUI.TableViewCell:new(); --caching cells so they dont need to be recreated everytime reload Data is called.
tData.cells[rowIndex][columnIndex].value=tData.mpgames[rowIndex][columnIndex];
return tData.cells[rowIndex][columnIndex]; --returns a cell
end
function tData:numberOfRows ()
--tableview queries the number of rows in table.
return #tData.mpgames
end
function tData:numberOfColumns ()
--tableview queries the number of columns in table.
return #tData.headers
end
function tData:sortColumn (columnIndex, ascending)
--tableview requests column to be sorted ; implement sort here
table.sort(tData.mpgames, function(rowA,rowB)
if (ascending) then
return rowA[columnIndex] < rowB[columnIndex]
else
return rowA[columnIndex] > rowB[columnIndex]
end
end)
self:reloadData()
end
local aTableView=LoveUI.TableView:new(LoveUI.Rect:new(400, 300, 250, 250), tData) --make tableView with data object
--add the views to context
aContext:addSubview(aTableView);