Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2579] Table EventListener e.index does not return correct row index

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2012-09-26T18:25:58.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsTi.UI.SIZE, andoid, classname, eventlistener, mobile, mobilesdk, tableView, tableviewrow
ReporterDavid Zollinger
AssigneeMauro Parra-Miranda
Created2012-08-11T15:41:11.000+0000
Updated2016-03-08T07:41:39.000+0000

Description

When building a tableview based on existing data, the table eventlistener 'click' does not return the correct index value for the row clicked on. Instead it returns the index value of the last item in the list. This issue can be fixed by removing the 'className' from the tableviewrow definition. Additionally it can be fixed by removing 'height: Ti.UI.SIZE' from the tableview definition. It seems that these two options used at the same time in a table break the click function. One last thing, if you force the view to redraw, by switching orientation for example, after the redraw the index value returned from the click event is correct. Here is a link to some extensive testing from the Q&A forum: [http://developer.appcelerator.com/question/140856/removing-a-tableviewrow-works-on-ios-but-not-android] Here is code to reproduce the issue:
var win = Ti.UI.createWindow({ backgroundColor:'white' });
var data = [
    { title: 'One', productID: 1, productQty: 10 },
    { title: 'Two', productID: 2, productQty: 9 },
    { title: 'Three', productID: 3, productQty: 8 },
    { title: 'Four', productID: 4, productQty: 7 },
    { title: 'Five', productID: 5, productQty: 6 }
];
var intRow = 0, intRows = data.length;
var tbl_data = [];
var cartRow;
for (intRow = 0; intRow < intRows; intRow = intRow + 1) {
    cartRow = Ti.UI.createTableViewRow({        
        className: 'mydata'
    });
 
    var deleteBtn = Ti.UI.createButton({
        right: 0,
        height: 45,
        width: 45,
        action: 'remove',
        title: 'r',
        productID: data[intRow].productID
    });
 
    cartRow.add(deleteBtn);
    tbl_data.push(cartRow);
}
 
var table = Ti.UI.createTableView({
    backgroundColor: 'red',
    data:tbl_data,
    height:Ti.UI.SIZE       
});
 
Ti.API.info('length', tbl_data.length);
win.add(table);
 
table.addEventListener('click', function(e){
    Ti.API.info('delete > index ' + e.index);
});
 
win.open();

Comments

  1. Karl Rowley 2012-09-26

    This is a duplicate of TIMOB-10712 I'm not able to reproduce this bug when I apply these pending pull requests: https://github.com/appcelerator/titanium_mobile/pull/3043 https://github.com/appcelerator/titanium_mobile/pull/3033
  2. Mauro Parra-Miranda 2013-11-24

    DUP issue.

JSON Source