TableView and Rows

You must Login before you can answer or comment on any questions.

hi there, i can push the data to tableview but i couldn't figure how to do this with tableviewrows? because i must to add images and customize the fonts

list.js

Ti.include("functions.js");
var data = []; //empty data array
 
var tblFavorites = Titanium.UI.createTableView({
          top: 0,
          left: 0,
          color:'#e8e8e8'
 
});
 
mywindow.add(tblFavorites);
 
function loadFavorites(){
     data = []; //set our data object to empty
     data = getFavorites();
     tblFavorites.data = data;     
}
   //the focus event listener will ensure that the list
   //is refreshed whenever the tab is changed
 
mywindow.addEventListener('focus', loadFavorites);
functions.js
function getFavorites() {
     var db = Ti.Database.open('mydb');
     var sql = "SELECT id,baslik FROM liste ORDER BY baslik ASC";
     var results = [];
     var resultSet = db.execute(sql);
     while (resultSet.isValidRow()) {
       results.push({
         id: resultSet.fieldByName('id'),
         title: resultSet.fieldByName('baslik')
                                    });
       //iterates to the next record
       resultSet.next();
     }
     //you must close the resultset
     resultSet.close();
     db.close();
     //finally, return our array of records!
     return results;
}
and for my query this is not working
var kategori = 3;
var sql = "SELECT * FROM klipler WHERE kategori ="+ kategori +" kategori ORDER BY baslik ASC";
what should i use ?

Thanks

— asked 9 months ago by Graham Jeffrey
8 Comments
  • to resolve your query issue we need information about how the table is structured

    — commented 9 months ago by Aaron Saunders

  • Aaron hello, i am asking how must i write the sql variable for pulling the "kategori" section dynamically? if i write like this it works,

    var sql = "SELECT * FROM klipler WHERE kategori = 2  ORDER BY baslik ASC";
    but when i write like this it doesn't work
    var sql = "SELECT * FROM klipler WHERE kategori ="+ kategori +"  ORDER BY baslik ASC";

    — commented 9 months ago by Graham Jeffrey

  • i have chaged the code like this and it works great, is it true method?

    dbrows = db.execute('SELECT * FROM klipler WHERE kategori = ? ORDER BY baslik ASC',kategori);

    — commented 9 months ago by Graham Jeffrey

  • Show 5 more comments

2 Answers

Accepted Answer

There are examples of this in the kitchen sink application, you should check it out.

Basically just create TableViewRow object, add content and add that object to an array. Build your array and set that as data in your tableview.

var data = [];
 
data[0] = Ti.UI.createTableViewRow({hasChild:true,title:'Row 1'});
data[1] = Ti.UI.createTableViewRow({hasDetail:true,title:'Row 2'});
data[2] = Ti.UI.createTableViewRow({hasCheck:true,title:'Row 3'});
data[3] = Ti.UI.createTableViewRow({title:'Row 4'});
 
// create table view
var tableview = Titanium.UI.createTableView({
    data:data
});

Your Answer

Think you can help? Login to answer this question!