'database' and 'MUI.table'

169 views
Skip to first unread message

Stephan Stadler

unread,
Jul 1, 2022, 2:13:24 PM7/1/22
to DroidScript
I find samples for working with 'database', I also find samples for working with 'MUI.table'.
But I do not succeed in joining both topics.
I'm looking for a small solution to show all "firstnames, lastnames, adresses" in a database in that MUI.table and to add an new contact/adress to table and database.
Does anybody know a sample, I can learn about this?
Thank you!

Alan Hendry

unread,
Jul 1, 2022, 4:16:05 PM7/1/22
to DroidScript
HI,
Starting with the database sample (typing this in here, so there may be typos etc)
Change the database table create for your fields
        "(id integer primary key, firstname text, lastname text, address text)" )  
At the beginning of function OnResult( results ) create the table but with no data
        var headers = ["ID", "FirstName", "LastName", "Address"]
        var table = MUI.CreateDataTable(headers, "", 0.96, 0.6)
        lay.AddChild(table)
Put each row in the table
      for (var i = 0; i < results.rows.length; i++ ) {  
        var item = results.rows.item(i)  
        table.AppendRow(item.id + ": " + item.firstname + ": " + item.lastname + ": " + item.address)
     }  
(remove everything for field txt)
 Regards, ah

Stephan Stadler

unread,
Feb 10, 2023, 10:07:09 AM2/10/23
to DroidScript
That doesn't work any more.
I get the following message:
  • Script Error: AppendRow is not defined, Line 1, undefined
what's going wrong???

Right2TheV0id

unread,
Feb 10, 2023, 5:48:20 PM2/10/23
to DroidScript
When you'll get your invitation to the premium forum you should look at this post:

Jumar

unread,
Feb 10, 2023, 7:58:17 PM2/10/23
to DroidScript
I just want to paste it here since some users get MUI from PlayStore

You need to make sure that the Table control is fully loaded before calling any methods that will update the data such as AppendRow, SetRows, RemoveRows and the likes.

Try this

cfg.Light
cfg.MUI

function OnStart()
{
    lay = MUI.CreateLayout("Linear", "FillXY,VCenter")
    
    var values1 = [ "John:24:deepPurple", "Jane:22:deepPurple", "Jonathan:26:deepPurple" ]
        
    var values2 = [ "Doe:12:deepPurple", "Dawn:20:deepPurple", "Dane:16:deepPurple" ]

    table = MUI.CreateDataTable("Name,Age,Color",values1, 1, 0.4, 'selectable')
    lay.AddChild(table);
    
    setTimeout(function() {
        table.SetRows(values2)
    }, 2000)
    
    app.AddLayout(lay)
}

Regards
Jumar

Stephan Stadler

unread,
Feb 11, 2023, 6:38:56 AM2/11/23
to DroidScript
Hey, that works!!!
Thanx to Jumar. Well done.
I would never find out by myself.
Problem solved!

Right2TheV0id

unread,
Feb 11, 2023, 4:07:04 PM2/11/23
to DroidScript
There is now a table.SetOnReady() method, but it is not present in the built-in documentation.
You can check the online documentation, which is more up to date:
Reply all
Reply to author
Forward
0 new messages