Connecting the List Viewer to the on-device data

Global variables to store datastore information are defined in the master page immediately after the script tag:

// on-device data object name... 
var dbmgr; 
// account datastore name... 
var accountDb; 
// array for account sort order options... 
var accountSortOrderArray = new Array(3) 
// array for account column internal labels... 
var accountCols = new Array(3);

Within the body tag of the master page, the initPage() function is set to execute immediately when the page is loaded:

<body onload="initPage()" onUnload="exitPage()">

The initPage() function stores the "Customers" datastore name in a variable and opens the on-device datastore:

var dbname = "Customers"; 

if (undefined == dbmgr) { 
    dbmgr = CreateObject('avantgo.db'); 
}
if (null == dbmgr) { 
    alert('Error: unable to create avantgo.db'); 
    return false; 
} 

accountDb = dbmgr.open(dbname, "r"); 
if (null == accountDb) { 
    alert("failed to open db"); 
    return; 
}

The initPage() function then sets up the List Viewer object:

list = document.getElementById("accountTable");
list.setDbSet(accountDb);

And lastly the initPage() function sets the attributes the List Viewer object will need to display the data:

list.setColumnCount(3);

list.setColumnTitle(0, "Customer"); 
list.setColumnWidth(0, 60); 
list.setColumnDSName(0, "ContactName"); 
list.setColumnHeaderImage(0, 1);
list.setColumnTitle(1, "Company"); 
list.setColumnWidth(1, 60); 
list.setColumnDSName(1, "CompanyName"); 
list.setColumnHeaderImage(1, 1);

list.setColumnTitle(2, "Postal Code"); 
list.setColumnWidth(2, 40); 
list.setColumnDSName(2, "PostalCode");
Note

Labels in setColumnDSName() functions must match the data object labels in the XML data file downloaded to the device.

In summary, the List Viewer object is a convenient tool to provide user access to large datasets. Other approaches involving the dynamic generation of a table are more resource-intensive and cause more user perceivable transitions as the page is regenerated for searches and sorting. This functionality is currently supported by the M-Business XML datastore and is not available for UltraLite development.