Issue with a newTableView not populating (using sqlite3 database tutorial)

I have created a sqlite database and strictly following the Corona University Tutorial I am unable to populate the table.

The table shows up with the proper number of rows (based on the size of the table) It performs as expected.

I tested the for loop with print statements to see if the information was being imported from the database and like a charm all fields are populating to the terminal just fine.

inside the onRowRender function I attempted to print the values using row.params.<variable> as well as a simple row.<variable> and I get nothing, just like the table.

So the values are not being passed to the onRowRender function as far as I can tell. . . But not sure what the issue is.

Any help would be great.

Thanks

[lua]


– SQL TABLE – CREATE TABLEVIEW WIDGET


    local table_options = {

        

        top = _H * 0.1,

        height = _H * 0.8,

        backgroundColor = { 0.8, 0.8, 0.8 },

        onRowRender = onRowRender,

    }

    

    local tableView = widget.newTableView( table_options)

    


– SQL TABLE – RETRIEVE DATA FROM DATABASE


    for row in db:nrows(“SELECT * FROM input”) do

        

------------------------------------------------        

–     TESTING READING OF DATABASE ELEMENTS

        print(row.id)

        print(row.capture)

        print(row.timeDate)

------------------------------------------------ 

        --parameters for lua table

        local rowParams = {

            id = row.id,

            capture = row.capture,

            timeDate = row.timeDate,

        }

        

        – add tableview row

        tableView:insertRow(

            {

            rowHeight   = 50,

            params      = rowParams,

            }

        )

    end

    

 ---------------------------------------------------------------------------------

– SQL TABLE – HANDLE TABLEVIEW RENDERING  

---------------------------------------------------------------------------------   

    

    local function onRowRender ( event )

        

        local row = event.row

       

        print(row.id)

        print(row.capture)

        print(row.timeDate)

        

        

        – common row elements

        local font      = native.systemFont

        local fontSize  = 24

        local rowHeight = row.height / 2

        – display.newText options

        local options_id = {

            parent   = row,

            text     = row.params.id,

            x        = 50,

            y        = rowHeight,

            font     = font,

            fontSize = fontSize,

        }

        

        – add row objects

        row.id      = display.newText( options_id )

        row.id.anchorX  = 0

        row.id:setFillColor( 1, 0, 0 )

        

        – display.newText options

        local options_capture = {

            parent   = row,

            text     = row.params.capture,

            x        = 100,

            y        = rowHeight,

            font     = font,

            fontSize = fontSize,

        }

        

        – add row objects

        row.capture      = display.newText( options_capture )

        row.capture.anchorX  = 0

        row.capture:setFillColor( 1, 0, 0 )

        

        – add row objects

        row.id      = display.newText( options_id )

        row.id.anchorX  = 0

        row.id:setFillColor( 1, 0, 0 )

        

        – display.newText options

        local options_timeDate = {

            parent   = row,

            text     = row.params.timeDate,

            x        = 200,

            y        = rowHeight,

            font     = font,

            fontSize = fontSize,

        }

        

        – add row objects

        row.timeDate      = display.newText( options_timeDate )

        row.timeDate.anchorX  = 0

        row.timeDate:setFillColor( 1, 0, 0 )

        

    end[/lua]

Anyone? Anyone?

I am experiencing the same kind of problem.  For the moment I am not populating from SQLite but I will be.  I get the same result.  Table has rows, table is populated but nothing displays.  I tried it in a previous version of the SDK, 2013.12.7.  Here is main.lua.  We seem to be doing things similarly.  This code comes from J.A. Whyte’s excellent tutorial videos for developing business apps in Corona called Business Apps Using Corona SDK.  As far as I can see this code has no problems.  Compiles fine but won’t display the data.  I’d like to know how to tell if the data from the initial table is making it into the WidgetView.   

local widget = require(“widget”)

    local top = display.statusBarHeight

    local listRecs ={}

    local list = nil

    local nameData = {“Smith”, “Johnson”, “Williams”, “Jones”, “Brown”, “Davis”, “Miller”, “Wilson”, “Moore”, “Taylor”, “Anderson”, “Thomas”, “Jackson”, “White”, “Harris”}

    local function setup()

   local bg = display.newRect(0,top, display.contentWidth, display.contentHeight - top)

   bg:setFillColor(0,155,73)

   list = widget.newTableView {top = top +10, height = 450 }

   --maskFile = “mask.png”

    end

    local function loadData()

   for x =1 , #nameData do

   listRecs[x] = {}

   listRecs[x].name = nameData[x]

   listRecs[x].age = math.random(18,35)

   listRecs[x].showDel = false

print(listRecs[x].name…" "…listRecs[x].age)

   end

    end

    local function showRecords()

   local function onRowRender(event)

   local row = event.row

   local rowGroup = event.view

   local idx = row.index or 0

   local color = 0

print("the index value is: "…idx)

 

    row.textObj = display.newRetinaText(listRecs[idx].name, 0, 0, “Helvetica”, 16)

   row.textObj:setTextColor( color )

   row.textObj:setReferencePoint(display.CenterLeftReferencePoint)

   row.textObj.x = 20

   row.textObj.y = rowGroup.contentHeight*0.35

   row.textObj2 = display.newRetinaText(listRecs[idx].age, 0, 0, “Helvetica”, 16)

   row.textObj2:setTextColor( color )

   row.textObj2:setReferencePoint(display.CenterLeftReferencePoint)

   row.textObj2.x = 20

   row.textObj2.y = rowGroup.contentHeight*0.65

   rowGroup:insert(row.textObj)

   rowGroup:insert(row.textObj2)

    end – onRowRender

   local function rowListener(event)

   end – row Listener

   for x = 1, #listRecs do

   list:insertRow{

   onRender = onRowRender,

   listner = rowListener

}

   end

    end – showRecords

    setup()

    loadData()

    showRecords()

Note, the line print("the index value is: "…idx) returns nothing.

Hey GuyDuff,

Glad to see I’m not the only one having an issue. . . I’m pretty new to this myself and I have seen some of Jay’s stuff, which I like, but a lot of it I’ve found to be outdated (probably not significantly though).

The only thing I notice is that you have setTextColor set to 0. Looked at the documentation and couldn’t see how that would work. 

 also check out Post Formatting at the bottom of the “Reply to this topic”  it shows you how to format your lua code :slight_smile:

James

Hi James,

Got this back from Jay.  Seems the widget library has changed since he created that video.  He is working on updating the tutorial.  In the meantime, here is the answer, at least for my code:

add the following line of code: 

local widget = require(“widget-v1”)

then add widget-v1.lua file to your project.  

you can get the legacy widget library here: https://github.com/coronalabs/widget-v1

Apparently in the old syntax you can set the color to just 0.  I saw it work in Jay’s videos.  I’ll grapple with the new graphics later and for the time being I’m setting “graphicsCompatibility = 1” in my config.lua.  

 

I’m pretty new to Corona too and have only had a few dozen hours to commit to learning it.  Jay is in this community.  Maybe you could send him a personal message and he can help.  I know he is busy but he is really cool and I know he would spot the problem.  In any case, I’m going to download the legacy Widget Library and give it a go.

 

I’ll keep following this thread. 

Cheers,

Guy

I have had the same problem and also with Jay’s videos.   I even used the widget-v1 that Jay suggested but still nothing.

I even used this code from this site (http://coronalabs.com/blog/2014/03/04/tutorial-advanced-tableview-tactics/)

But I still can’t get the data to populate the screen.

 (FYI: you’ll also need to remove all of the setReferencePoint stuff to be anchorX and anchor.Y).  

Love to hear what the solution is to get the data to show.

Thanks for the update Guy.

I know that Corona is ever changing and evolving. I’m hoping to stay as current as possible and hopefully save myself some time and headaches in the future. 

I own Jay’s Outlaw IDE, but I use Glider. I’ve found it just works better for me since I’m a Netbeans user. I will send him a message and see what he says. I will update here if I figure out the issue.

James

Okay, I think I’ve found the culprit. That being said, I don’t know how to fix it.

I wasn’t passing the parameters to the onRowRender Function because of it’s placement in the code. I moved it and tested it with print statements and I’m getting all my variables populating inside the onRowRender Function. However, no dice on getting the Table to populate. So doing some further digging I found an issue with the  display.newText function which reads:

Gotchas

The newText() object uses a mask when the object is created. Since there is a  nested  mask limit of three on all platforms, care must be taken when inserting text into acontainerScrollView, or TableView (these also consume a mask unit). If you exceed the mask nesting limit, the text may appear as a solid white block.

ScreenShot2014-05-15at104045PM.png

As far as I can tell I’m just getting white blocks like the GOTCHAS section describes.

But I have no idea how to fix the issue with the little documentation provided. I have tried only populating the id, removing all un required fields, etc. But no luck.

Here is my code for anyone who thinks they have an answer. Thanks in advance.

[lua]–TABLE VIEW OF DATABASE

    -------------------------------------------------------

    – HANDLE TABLEVIEW ROW RENDERING

    -------------------------------------------------------

    local function onRowRender ( event )

        

        local row = event.row

        

            print(row.params.id)

            print(row.params.capture)

            print(row.params.timeDate)

        – common row elements

        local font = native.systemFont

        local fontSize = 24

        local rowHeight = row.height / 2

        

        – display.newText options

        local options_id = {

            parent = row,

            text = row.params.id,

            x = 50,

            y = rowHeight,

            font = font,

            fontSize = fontSize,

        }

        

        – add row object

        row.id = display.newText ( options_id )

        row.id.anchorX = 0

        --row.id:SetFillColor( 1, 0, 0 )

        

        – display.newText options

        local options_capture = {

            parent = row,

            text = row.params.capture,

            x = 100,

            y = rowHeight,

            font = font,

            fontSize = fontSize,

        }

        

        – add row object

        row.capture = display.newText ( options_capture )

        row.capture.anchorX = 0

        --row.capture:SetFillColor( 1, 0, 0 )

        

        – display.newText options

        local options_timeDate ={

            parent = row,

            text = row.params.timeDate,

            x = 200,

            y = rowHeight,

            font = font,

            fontSize = fontSize,

        }

        

        – add row object

        row.timeDate = display.newText ( options_capture )

        row.timeDate.anchorX = 0

        --row.timeDate:SetFillColor( 1, 0, 0 )

        

        

    end

    -------------------------------------------------------

    – 

    –  CREATE TABLEVIEW WIDGET

    –

    -------------------------------------------------------

    

    local table_options = {

        

        top = _H * 0.5,

        left = _W * 0.05, – 1/2 of the remainder of the Window

        width = _W * 0.9, – 90% of the window width

        height = _H * 0.4,

        listener = tableViewListener,

        backgroundColor = { 0.95, 0.95, 0.95 },

        onRowRender = onRowRender,

        

    }

    

    local tableView = widget.newTableView( table_options ) 

    

    

    -------------------------------------------------------

    – 

    – RETREIVE DATABASE DATA

    – 

    --------------------------------------------------------- 

    for row in db:nrows(“SELECT * FROM input”) do

        

    ------------------------------------------------        

    –     TESTING READING OF DATABASE ELEMENTS

–            print(row.id)

–            print(row.capture)

–            print(row.timeDate)

    ------------------------------------------------ 

        

        --Parameter lua table

        local rowParams = {

            id = row.id,

            capture = row.capture,

            timeDate = row.timeDate

        }

        

        --Add tableView rows

        tableView:insertRow(

        {

            rowHeight = 50,

            params = rowParams,

        }

        )

    end[/lua]

Try explicitly inserting the display elements into the row view, like this: temp = display.newText(…) row:insert(temp) for each of your display objects in the row. Make sure you set the fill color as well. I’m using the latest public build:Starter v2014.2189 I also use Sqlite, and do queries, inserts, updates, and deletes into a tableview. It all seems to work well, except that there is a bug in the current public build mentioned above. Upon deleting a middle row in the tableview, you will notice display rows overlapping, and see missing horizontal lines. They have fixed this in a daily build, but those of us on the starter license won’t see this fixed until the next public build, hopefully soon! Good luck!

Awesome I will try that. Thanks for the reply

Bvsmailuser. Thanks for the recommendation. Got it working with about half the code that the Corona University Video shows.

Here is the final code to get it to work. At least show up on the table. I have a lot to add to it to get it to do exactly what I want, but now at least I can move forward.

[lua]


– SQL TABLE – HANDLE TABLEVIEW RENDERING  

---------------------------------------------------------------------------------   

    

    local function onRowRender ( event )

        

        local row = event.row

            

            local rowId = display.newText(row, row.params.id, 50, row.height / 2, system.nativeFont , 24)

            local rowCapture = display.newText(row, row.params.capture, 150, row.height / 2, system.nativeFont , 24)

            local rowtimeDate = display.newText(row, row.params.timeDate, 1350, row.height / 2, system.nativeFont , 24)

            rowId.anchorX = 0

            rowCapture.anchorX = 0

            rowtimeDate.anchorX = 1.0

            rowId:setTextColor(0,0,0)

            rowCapture:setTextColor(0,0,0)

            rowtimeDate:setTextColor(0,0,0)

    end

    

    


– SQL TABLE – CREATE TABLEVIEW WIDGET


    local table_options = {

        

        top = _H * 0.1,

        height = _H * 0.8,

        backgroundColor = { 1, 1, 1 },

        onRowRender = onRowRender,

    }

    

    local tableView = widget.newTableView( table_options)

    


– SQL TABLE – RETRIEVE DATA FROM DATABASE


    for row in db:nrows(“SELECT * FROM input”) do

        

—      TESTING READING OF DATABASE ELEMENTS

–        print(row.id)

–        print(row.capture)

–        print(row.timeDate)

------------------------------------------------ 

        --parameters for lua table

        local rowParams = {

            id = row.id,

            capture = row.capture,

            timeDate = row.timeDate,

        }

        

        – add tableview row

        tableView:insertRow(

            {

            rowHeight   = 50,

            params      = rowParams,

            }

        )

    end[/lua]

Corona437,

Glad you got it working!

Good luck,

BVS

Anyone? Anyone?

I am experiencing the same kind of problem.  For the moment I am not populating from SQLite but I will be.  I get the same result.  Table has rows, table is populated but nothing displays.  I tried it in a previous version of the SDK, 2013.12.7.  Here is main.lua.  We seem to be doing things similarly.  This code comes from J.A. Whyte’s excellent tutorial videos for developing business apps in Corona called Business Apps Using Corona SDK.  As far as I can see this code has no problems.  Compiles fine but won’t display the data.  I’d like to know how to tell if the data from the initial table is making it into the WidgetView.   

local widget = require(“widget”)

    local top = display.statusBarHeight

    local listRecs ={}

    local list = nil

    local nameData = {“Smith”, “Johnson”, “Williams”, “Jones”, “Brown”, “Davis”, “Miller”, “Wilson”, “Moore”, “Taylor”, “Anderson”, “Thomas”, “Jackson”, “White”, “Harris”}

    local function setup()

   local bg = display.newRect(0,top, display.contentWidth, display.contentHeight - top)

   bg:setFillColor(0,155,73)

   list = widget.newTableView {top = top +10, height = 450 }

   --maskFile = “mask.png”

    end

    local function loadData()

   for x =1 , #nameData do

   listRecs[x] = {}

   listRecs[x].name = nameData[x]

   listRecs[x].age = math.random(18,35)

   listRecs[x].showDel = false

print(listRecs[x].name…" "…listRecs[x].age)

   end

    end

    local function showRecords()

   local function onRowRender(event)

   local row = event.row

   local rowGroup = event.view

   local idx = row.index or 0

   local color = 0

print("the index value is: "…idx)

 

    row.textObj = display.newRetinaText(listRecs[idx].name, 0, 0, “Helvetica”, 16)

   row.textObj:setTextColor( color )

   row.textObj:setReferencePoint(display.CenterLeftReferencePoint)

   row.textObj.x = 20

   row.textObj.y = rowGroup.contentHeight*0.35

   row.textObj2 = display.newRetinaText(listRecs[idx].age, 0, 0, “Helvetica”, 16)

   row.textObj2:setTextColor( color )

   row.textObj2:setReferencePoint(display.CenterLeftReferencePoint)

   row.textObj2.x = 20

   row.textObj2.y = rowGroup.contentHeight*0.65

   rowGroup:insert(row.textObj)

   rowGroup:insert(row.textObj2)

    end – onRowRender

   local function rowListener(event)

   end – row Listener

   for x = 1, #listRecs do

   list:insertRow{

   onRender = onRowRender,

   listner = rowListener

}

   end

    end – showRecords

    setup()

    loadData()

    showRecords()

Note, the line print("the index value is: "…idx) returns nothing.

Hey GuyDuff,

Glad to see I’m not the only one having an issue. . . I’m pretty new to this myself and I have seen some of Jay’s stuff, which I like, but a lot of it I’ve found to be outdated (probably not significantly though).

The only thing I notice is that you have setTextColor set to 0. Looked at the documentation and couldn’t see how that would work. 

 also check out Post Formatting at the bottom of the “Reply to this topic”  it shows you how to format your lua code :slight_smile:

James

Hi James,

Got this back from Jay.  Seems the widget library has changed since he created that video.  He is working on updating the tutorial.  In the meantime, here is the answer, at least for my code:

add the following line of code: 

local widget = require(“widget-v1”)

then add widget-v1.lua file to your project.  

you can get the legacy widget library here: https://github.com/coronalabs/widget-v1

Apparently in the old syntax you can set the color to just 0.  I saw it work in Jay’s videos.  I’ll grapple with the new graphics later and for the time being I’m setting “graphicsCompatibility = 1” in my config.lua.  

 

I’m pretty new to Corona too and have only had a few dozen hours to commit to learning it.  Jay is in this community.  Maybe you could send him a personal message and he can help.  I know he is busy but he is really cool and I know he would spot the problem.  In any case, I’m going to download the legacy Widget Library and give it a go.

 

I’ll keep following this thread. 

Cheers,

Guy

I have had the same problem and also with Jay’s videos.   I even used the widget-v1 that Jay suggested but still nothing.

I even used this code from this site (http://coronalabs.com/blog/2014/03/04/tutorial-advanced-tableview-tactics/)

But I still can’t get the data to populate the screen.

 (FYI: you’ll also need to remove all of the setReferencePoint stuff to be anchorX and anchor.Y).  

Love to hear what the solution is to get the data to show.

Thanks for the update Guy.

I know that Corona is ever changing and evolving. I’m hoping to stay as current as possible and hopefully save myself some time and headaches in the future. 

I own Jay’s Outlaw IDE, but I use Glider. I’ve found it just works better for me since I’m a Netbeans user. I will send him a message and see what he says. I will update here if I figure out the issue.

James