widget.newTableView() and categories

Hi

I’m trying to insert some categories into my TableView like so; 

[lua]

for i=1,400 do

if i == 2 then

       myList:insertRow{

       rowHeight = 30,

       isCategory = true,

     rowColor = {default={ 255,0,0 }, over={ 255, 0, 0, 1 }},

    lineColor = {default={ 0, 0, 0 }, over={ 0, 0, 0, 1 }},

     }

elseif i == 307 then

       myList:insertRow{

       rowHeight = 30,

       isCategory = true,

     rowColor = {default={ 255,0,0 }, over={ 255, 0, 0, 1 }},

    lineColor = {default={ 0, 0, 0 }, over={ 0, 0, 0, 1 }},

     }

else

   myList:insertRow{

      rowHeight = 60,

      isCategory = false,

      rowColor = {default={ 255, 255, 255 }, over={ 205, 255, 255, 1 }},

      lineColor = {default={ 0, 0, 0 }, over={ 0, 0, 0, 1 }},

   }

end

end

[/lua]

However, I do not know what to do in my onRowRender function - currently I have this situation:

[lua]

local function onRowRender( event )

   --Set up the localized variables to be passed via the event table

   local row = event.row

   local id = row.index

if id == 2 then – id = 2 is a category as defined in my for loop

else

   nameText = display.newText(person[id].name, 20, 0, native.systemFontBold, 18 )

   nameText:setTextColor(0,0,0)

   nameText.y = 20

   phoneText = display.newText( person[id].phone, 20, 0, native.systemFont, 18 )

   phoneText:setTextColor( 0,0,0 )

   phoneText.y = 40

end 

   

   return true

end

[/lua]

However, the 2nd item in my table is not dealt with and this means that I’m missing data. I tried without the if condition, but that caused my table data to be added to the category row.

Sorry if that’s not clear, I’m happy to clarify if necessary

Thanks

max

I think you missunderstood the category concept. Category is not supposed to be one of your data rows. It is supposed to be an additional row and you have to draw it’s content also based on event.row.isCategory. So if you want a new category to start before row 2 you should insert the category row and the row 2 also (remove the else add it in any situation).

Remebmer you have to add any text you want in the category in onRowRender.

the only problem is that categories are counted in the id count, and so my table call with [id] results in the wrong info being placed in the rows. That’s why I have the if else statement

Am I missing something obvious here? 

Thanks

Max 

You can set whatever id you want in the insertRow just add id = i for normal row and something different like id = “group”…tostring(i) for the group rows.

I think you missunderstood the category concept. Category is not supposed to be one of your data rows. It is supposed to be an additional row and you have to draw it’s content also based on event.row.isCategory. So if you want a new category to start before row 2 you should insert the category row and the row 2 also (remove the else add it in any situation).

Remebmer you have to add any text you want in the category in onRowRender.

the only problem is that categories are counted in the id count, and so my table call with [id] results in the wrong info being placed in the rows. That’s why I have the if else statement

Am I missing something obvious here? 

Thanks

Max 

You can set whatever id you want in the insertRow just add id = i for normal row and something different like id = “group”…tostring(i) for the group rows.