TableView - How to access tableView view in widget 2.0?

I’m trying to convert my code from the widget 1 to widget 2 library, but I’m having some problems.

I was originally passing some data to the row when called list:insertRow(), but that no longer works, or at least I can no longer access the data.  I also cannot access to group to insert.

Previously I did the following:

-- onRender listener for the tableView local function onRowRender( event ) print( "rendered" ) local row = event.target local rowGroup = event.view row.title = row.data.title row.description = row.data.description -- Title local title = txt.new( row.title, 12, 0, native.systemFontBold, 14 ) title:setTextColor( 255, 255, 255 ) title:setReferencePoint( display.CenterLeftReferencePoint ) title.x = 30; title.y = 10 -- must insert everything into event.view: rowGroup:insert( title ) rowGroup:insert( rightArrow ) end -- List local listOptions = { top = 120, height = 380, width = display.contentWidth, maskFile = "images/mask320x390.png", listener = tableViewListener, hideBackground = true, } list = widget.newTableView( listOptions ) --Data fed from a JSON feed into 'data' -- function below is responsible for creating the row list:insertRow{ height=rowHeight, isCategory=isCategory, rowColor=rowColor, lineColor=lineColor, data=data[i],      onRowTouch = onRowTouch,      onRowRender = onRowRender, }

This worked fine.  Then when I updated I needed to move the render and touch events round, but it also meant that event.target and event.view were no longer available in the onRowRender method.  How can I now access them in widget2?

Hi @mike22,

Did you see the Widgets 2.0 Migration guide yet?

http://docs.coronalabs.com/api/library/widget/migration.html

This might help with your issue.

Brent

Hi Brent,

Yes, I followed that guide initially, but it doesn’t show how to access to view or the attached row data.

I have tried printing the members of the lua object/table that is passed to the onRowRender method (event), but none of the properties (or sub-properties) contain my attached data.  So, how can I pass it?  This must be a very common problem.

Thanks

Hi Brent, 

funny, just had the same question. Where did the view go ?  its not in the migration guide !

  1. Why is it missing in the migration guide ?

  2. What to use instead ? 

  3. How does onRowRender pass the (which) display objects back ? How to insert multiple objects in the display group ?

Shouldnt’ this be part of a QA teams use cases ?

Thanks a lot

Frank

You can attach stuff to event.row I’ve found, it acts as the row’s group/view.

That still doesn’t answer my question on how I can pass data around though.  Currently I have a table and I’m referencing it by the table index.  This is far from ideal, as the table might have missing keys (not in my case, luckily).  I want different behaviour for manually inserted rows (think isCategory, but different) - this was easy before as I could just pass anything in the list:insertRow() call, but it’s now looking to be impossible.

Before:

list:insertRow{ onRender=unpaidRender, rowHeight=12, isCategory = isCategory, lineColor = { 174, 51, 51, 0 }, rowColor = rowColor, customData = 'Hello there' }

So how would I pass/access ‘customData’ now?

I’m still having no luck with this.  In certain circumstances I can populate an array/table with data externally (eg outside of the loop that populates the table) and then reference that array/table inside the touch event, but as I’m adding different sources of data to the same table that isn’t an option for me.

This is a must-have that has just been removed from version 1 to version 2 of the widget library.  I cannot believe this has gone unnoticed, there has to be a way to pass/attach data to the row when inserting it.

I am jamming data into my rows also, but differently than you are… Adapting it to store it at table creation, you would need to add something like this right after each row insert:

list._view._rows[#list._view._rows].customData = “Hello there”

It may not be supported, it may not be pretty, but the general tactic seems to work for me (for now).

Great, thanks, will take a look.  Bit worrying that there’s no official way to attach data to something as obvious as a tablerow, especially when it previously worked perfectly.  The worry is in case this is removed in the future for some reason.  I guess I don’t have a huge choice though.

Thanks again

Hi @mike22,

Did you see the Widgets 2.0 Migration guide yet?

http://docs.coronalabs.com/api/library/widget/migration.html

This might help with your issue.

Brent

Hi Brent,

Yes, I followed that guide initially, but it doesn’t show how to access to view or the attached row data.

I have tried printing the members of the lua object/table that is passed to the onRowRender method (event), but none of the properties (or sub-properties) contain my attached data.  So, how can I pass it?  This must be a very common problem.

Thanks

Hi Brent, 

funny, just had the same question. Where did the view go ?  its not in the migration guide !

  1. Why is it missing in the migration guide ?

  2. What to use instead ? 

  3. How does onRowRender pass the (which) display objects back ? How to insert multiple objects in the display group ?

Shouldnt’ this be part of a QA teams use cases ?

Thanks a lot

Frank

You can attach stuff to event.row I’ve found, it acts as the row’s group/view.

That still doesn’t answer my question on how I can pass data around though.  Currently I have a table and I’m referencing it by the table index.  This is far from ideal, as the table might have missing keys (not in my case, luckily).  I want different behaviour for manually inserted rows (think isCategory, but different) - this was easy before as I could just pass anything in the list:insertRow() call, but it’s now looking to be impossible.

Before:

list:insertRow{ onRender=unpaidRender, rowHeight=12, isCategory = isCategory, lineColor = { 174, 51, 51, 0 }, rowColor = rowColor, customData = 'Hello there' }

So how would I pass/access ‘customData’ now?

I’m still having no luck with this.  In certain circumstances I can populate an array/table with data externally (eg outside of the loop that populates the table) and then reference that array/table inside the touch event, but as I’m adding different sources of data to the same table that isn’t an option for me.

This is a must-have that has just been removed from version 1 to version 2 of the widget library.  I cannot believe this has gone unnoticed, there has to be a way to pass/attach data to the row when inserting it.

I am jamming data into my rows also, but differently than you are… Adapting it to store it at table creation, you would need to add something like this right after each row insert:

list._view._rows[#list._view._rows].customData = “Hello there”

It may not be supported, it may not be pretty, but the general tactic seems to work for me (for now).

Great, thanks, will take a look.  Bit worrying that there’s no official way to attach data to something as obvious as a tablerow, especially when it previously worked perfectly.  The worry is in case this is removed in the future for some reason.  I guess I don’t have a huge choice though.

Thanks again