i want to get selected row value from tableview and copy into textfiled for appcelerator
Asked Answered
E

5

6

hi all i want to get selected row value into textfield so how can i copy the value into the textfiled. so how can i do this...my_combo is textfiled Code -:

var Tab_data = [

     { title:'Row 1', hasChild:true },
     { title:'Row 2', hasChild:true },
     { title:'Row 3', hasChild:true },
     { title:'Row 4', hasChild:true }
];


var tab = Titanium.UI.createTableView({
    top:43,
    data:Tab_data
});

tab.selectionIndicator=true;

tab.addEventListener('click',function(e) {

    var ind = e.index;

    if(e.selectRow)
    {
        Titanium.API.inof(' Selected clicked');
        my_combo.value = e.selectRow.title;
    } 

});
Entwine answered 11/5, 2011 at 12:16 Comment(0)
M
13

1) Create the row and attach the rowid to it, or whatever other data you want to associate to a row.

var row = Ti.UI.createTableViewRow();
row.rowId = 1;
row.myText = "hello world";

2) Add click event listener to the table:

tableView.addEventListener('click', selectRow);

3) In selectRow function, get the data.

function selectRow(e) {
 var rowId = e.rowData.rowId;
 var myText = e.rowData.myText;
 myTextField.value = myText;
}
Maloney answered 13/5, 2011 at 2:49 Comment(2)
Thanks for your help... i have another problem that how can i use soap based webservice in my apps. kitchensink ex. is not worked properly so can u give me any tutorial or code for it.Entwine
Under Titanium v3.0 I had to add my additional properties in the method constructor as shown here: developer.appcelerator.com/question/135791/…. E.g. var row = Titanium.UI.createTableViewRow({ target: tableOptions[i].target }); - I could then use e.rowData.target in my event handler function.Stockdale
D
0

You can just simply add 'rowid' to each row. And make an eventListener on your table like you did and retrieve the value with 'e.row.rowid'.

Deice answered 11/5, 2011 at 14:25 Comment(2)
Close, however I think it should be e.rowData.rowid. If e.row works as well then let me know, I've never tried that.Maloney
Thanks for your help... i have another problem that how can i use soap based webservice in my apps. kitchensink ex. is not worked properly so can u give me any tutorial or code for it.Entwine
P
0

you should put in constructor like this

var row = Titanium.UI.createTableViewRow({
    hasChild:true,
    title:rows.fieldByName('title'),
    rowId:rows.fieldByName('id'),
    path:'nextView.js'

    }); 
Presley answered 13/4, 2014 at 1:50 Comment(0)
E
0
tab.addEventListener('click',function(e) {

    var ind = e.index;

    if(e.selectRow)
    {
        Titanium.API.inof(' Selected clicked');
        my_combo.value = e.rowData.title;
    } 
});
Etruria answered 18/4, 2014 at 7:19 Comment(0)
R
0

Just replace e.selectRow with e.row in your code.

tab.addEventListener('click',function(e) {

    var ind = e.index;

    if(e.row)
    {
        Titanium.API.inof(' Selected clicked');
        my_combo.value = e.row.title;
    } 

});
Racing answered 18/4, 2014 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.