Rendering particular rows in tableview depending on data option

Hi
I have two tableviews. One tableview is the list of items which you can favorite and other is the list of items you’ve favorited. When I favorite one item (row #2 for instance), one item is displayed on the second list, though the content from the row#1 is displayed. It displays rows’ content one after another, not the content for the necessary rows.
My snippets of code:

favorite button function

 function onLikeSwitch( event ) likeSwitchPressed.alpha = 1 transition.to( likeSwitchPressed, {time =200, alpha =0} ) if liked[row.index] == false or liked[row.index] == nil then liked[row.index] = true likeSwitchSelect.alpha = 1 data[row.index].fav = true print (row.index,data[row.index].fav) print( "pressed" ) elseif liked[row.index] == true then likeSwitchSelect.alpha = 0 liked[row.index] = false data[row.index].fav = false end end

RowTitle from onrowrender
 

local rowTitle = display.newText( row, data[row.index].title, 0, 0, "Roboto-Regular", 12 ) rowTitle:setFillColor( .80, .333, 0)

for loop inserting rows

 for i = 1, #data do -- Insert a row into the tableView if data[i].fav == true then tableView:insertRow( { isCategory = false, rowHeight = 80, rowColor = { default={ .882, .925, .941}, over={ 1, 0.5, 0, 0.2 } }, lineColor = { .455, .616, .678 } } ) print ("hello",i, data[i].fav, data[i].title) else print (i, data[i].fav, data[i].title) end

I think I should change rowTitle to show not the data[row.index] but something else, but I can’t figure it out.
Thanks!

Another way you could tackle this is to do it all in one tableView. Create another element in your dataset to track the favoriting state. Use this element to create categorization in your single tableView. This way you can list a group at the top, say Favorites and then a category row breaking the two groups apart and then you list the non-favorites. This might be easier to implement. 

Thank you, but I’m not sure that I understand it well. You suggest setting favorited rows as category and then displaying only them?

Sorry for being vague. Let me expand. 

If you sort your data set like so

rowsTable = {

{rec1, john, favStateOn},

{rec2, jill, favStateOn},

{rec3, tim, favStateOn},

{rec4, ann, favStateOff},

{rec5, rob, favStateOff},

{rec6, lenny, favStateOff},

}

then you can run something like this (psuedo-code)

local currentFavState = nil

for i = 1, #rowsTable do

  if rowsTable[i][3] ~= currentFavState then 

      currentFavState = rowsTable[i][3]     <- 3rd element in record[i]

      insert category row using rowsTable[i][3] 

  end

  insert regular row using rowsTable[i] 

end

So your tableView will look like 

Favorites

    john

    jill

   tim

— show blank category row

   ann

   rob

   lenny

Hope this helps. You may want to review some of the Corona SDK samples, list1, list2, list3 and Widget Demo come to mind. These will show you how to insert categories and format them etc. 

Best of luck.

Another way you could tackle this is to do it all in one tableView. Create another element in your dataset to track the favoriting state. Use this element to create categorization in your single tableView. This way you can list a group at the top, say Favorites and then a category row breaking the two groups apart and then you list the non-favorites. This might be easier to implement. 

Thank you, but I’m not sure that I understand it well. You suggest setting favorited rows as category and then displaying only them?

Sorry for being vague. Let me expand. 

If you sort your data set like so

rowsTable = {

{rec1, john, favStateOn},

{rec2, jill, favStateOn},

{rec3, tim, favStateOn},

{rec4, ann, favStateOff},

{rec5, rob, favStateOff},

{rec6, lenny, favStateOff},

}

then you can run something like this (psuedo-code)

local currentFavState = nil

for i = 1, #rowsTable do

  if rowsTable[i][3] ~= currentFavState then 

      currentFavState = rowsTable[i][3]     <- 3rd element in record[i]

      insert category row using rowsTable[i][3] 

  end

  insert regular row using rowsTable[i] 

end

So your tableView will look like 

Favorites

    john

    jill

   tim

— show blank category row

   ann

   rob

   lenny

Hope this helps. You may want to review some of the Corona SDK samples, list1, list2, list3 and Widget Demo come to mind. These will show you how to insert categories and format them etc. 

Best of luck.