how do i add a line with content to table view

hi :slight_smile:

i have a tableView in my app, with is great and all but the thing is i want to add to it a new line with a new text every time

how can i do that ? i mean i now use :

 tableView:insertRow( { isCategory = isCategory, rowHeight = rowHeight, rowColor = rowColor, lineColor = lineColor, params = {} -- Include custom data in the row }

and i understood you need to render the lines in advance and then use it in the params section

but can someone post an example of how it is done ? how to change the content in that parmas section ?

and can’t i use something inside the line that i didn’t rendered in the beginning when i created the table view ?

thnx…

Hi Mars,

the way I do it is by having a separate array that holds the data I want to show… And in the onRowRender you just reference this array…

Something like this (pseudo code):

local tableContents = {} local function onRowRender( event ) local row = event.row local rowIndex = row.index local rowContent = tableContents[rowIndex] local text = display.newText( row, rowContent, 0, 0, 0,0,system.nativeFont, 14 ) end local function addLineToTable(lineText) tableContents[#tableContents + 1] = lineText tableView:insertRow{ isCategory = false, rowHeight = 100, rowColor = { default = { 255, 255, 255, 50 }, over={0, 0, 0, 0} }, lineColor = {0,0,0,100} } end addLineToTable("this is line #1") addLineToTable("this is line #2") addLineToTable("this is line #3")

Hi Mars, what @marcior said is correct.  The insertRow call basically handles creating the new row’s object and then it calls your defined onRowRender function passing you the display group (row) and the ID of the row.  You can then take that ID and look up data in a table external to the tableView and then create the necessary display items in that function and insert them into the row. 

Its kinda of an odd way of tracking your data and if you use category rows, it becomes a bit of a challenge since the category rows count towards the row’s index.

Then I saw a forum post the other day that was talking about the “params” option table being passed on the insertRow and after looking at the source code it looks like we have recently added support for this.  We have recently updated the docs to document this new feature.  Now to be honest I’ve not tried this but supposedly the idea is that you can now pass the params table during the insertRow call that has all the data in it you want the row to render and then in the onRowRender call you can can access event.row.params and you have that row’s data nice and convenient for you so you don’t have to look up an external table.  You can have different data for category rows if you like and make your onRowRender routine smart to know if it’s rendering a data row or a category row and just use the passed in params data.

I think once we have a change to write up a sample using it and perhaps a tutorial to go with it, this will make tableViews much more logical to understand.  The only drawback is that it’s going to be hard to update row data this way since you can’t really update the params after the fact, so be aware of that.

Rob

Hi Mars,

the way I do it is by having a separate array that holds the data I want to show… And in the onRowRender you just reference this array…

Something like this (pseudo code):

local tableContents = {} local function onRowRender( event ) local row = event.row local rowIndex = row.index local rowContent = tableContents[rowIndex] local text = display.newText( row, rowContent, 0, 0, 0,0,system.nativeFont, 14 ) end local function addLineToTable(lineText) tableContents[#tableContents + 1] = lineText tableView:insertRow{ isCategory = false, rowHeight = 100, rowColor = { default = { 255, 255, 255, 50 }, over={0, 0, 0, 0} }, lineColor = {0,0,0,100} } end addLineToTable("this is line #1") addLineToTable("this is line #2") addLineToTable("this is line #3")

Hi Mars, what @marcior said is correct.  The insertRow call basically handles creating the new row’s object and then it calls your defined onRowRender function passing you the display group (row) and the ID of the row.  You can then take that ID and look up data in a table external to the tableView and then create the necessary display items in that function and insert them into the row. 

Its kinda of an odd way of tracking your data and if you use category rows, it becomes a bit of a challenge since the category rows count towards the row’s index.

Then I saw a forum post the other day that was talking about the “params” option table being passed on the insertRow and after looking at the source code it looks like we have recently added support for this.  We have recently updated the docs to document this new feature.  Now to be honest I’ve not tried this but supposedly the idea is that you can now pass the params table during the insertRow call that has all the data in it you want the row to render and then in the onRowRender call you can can access event.row.params and you have that row’s data nice and convenient for you so you don’t have to look up an external table.  You can have different data for category rows if you like and make your onRowRender routine smart to know if it’s rendering a data row or a category row and just use the passed in params data.

I think once we have a change to write up a sample using it and perhaps a tutorial to go with it, this will make tableViews much more logical to understand.  The only drawback is that it’s going to be hard to update row data this way since you can’t really update the params after the fact, so be aware of that.

Rob