heirachical tables and tableView categories

Hi all,

I simply cant find a way to do this… hope its simple and im just missing something, it’s driving me a bit crazy!

I have a table that looks like this:

mytable["category1"] = { {name="row1"}, {name="row2"}, } mytable["category2"] = { {name="row3"}, {name="row4"}, } mytable["category3"] = { {name="row5"}, {name="row6"}, }

I want to create category rows for each category, and then have their child rows underneath each one.

The problem I keep running into is, in the rowRender listener for the tableView, I only have access to row.index to get data back out of the source table (“mytable”). I need to know the category too!
 

 This works:

local function onRowRender(event) local phase = event.phase local row = event.row local sometext = display.newText(mytable["category1"][row.index].name,0,0); sometext:setTextColor( {0,0,0} ) -- black row:insert(sometext) end

…But only for “category1” rows. But in place of [“category1”] here, I need to somehow pass in whether the data for that row is category1, category2, category3 according to the heiracy of “mytable”.

What’s the trick? 

Here’s what I was thinking / expecting to work somehow…

 

for key,value in pairs(mytable["category1"]) do myTableView:insertRow { isCategory = false, rowHeight = 23, rowColor = {0,0,0}, lineColor = {0,0,0}, categoryname = "category1" } end 

In the hope that I could then access “event.row.categoryname” or row.categoryname in my render function… no such luck though!

I solved this in the end by creating a flattened copy of my heirarchical object with the categories in. I can provide example code if it’s useful to anyone in the same boat as I was… just drop me a line or drop me a message on twitter (@jolleychris)

Here’s what I was thinking / expecting to work somehow…

 

for key,value in pairs(mytable["category1"]) do myTableView:insertRow { isCategory = false, rowHeight = 23, rowColor = {0,0,0}, lineColor = {0,0,0}, categoryname = "category1" } end 

In the hope that I could then access “event.row.categoryname” or row.categoryname in my render function… no such luck though!

I solved this in the end by creating a flattened copy of my heirarchical object with the categories in. I can provide example code if it’s useful to anyone in the same boat as I was… just drop me a line or drop me a message on twitter (@jolleychris)