Uploaded image for project: 'Appcelerator - INBOX'
  1. Appcelerator - INBOX
  2. AC-2579

Table EventListener e.index does not return correct row index

    Details

      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();
      

        Attachments

          Activity

            People

            • Assignee:
              mpmiranda Mauro Parra-Miranda
              Reporter:
              david@dzollinger.com David Zollinger
            • Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Integration