Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-540] Tableview.insertRowBefore(index, row, options) Inserts in wrong Index

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-10-27T15:52:02.000+0000
Affected Version/sRelease 1.6.2, Release 1.7.1
Fix Version/sSprint 2011-31, Release 1.8.0
ComponentsiOS
Labelstableview, tableviewrow
ReporterDawson Toth
AssigneeSabil Rahim
Created2011-04-15T02:31:27.000+0000
Updated2011-10-27T15:52:02.000+0000

Description

Problem

insertRowBefore adds rows at the incorrect spot.

Reproduction

Drop the following in an app.js. 1. It has a table with two rows: A and C. 2. It attempts to insert a row B before C. 3. The rows end up being BAC, instead of the expected ABC.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
win.open();

var data = [
    { title: 'A', name: 'A' },
    { title: 'C', name: 'C' }
];

var tableview = Ti.UI.createTableView({ data: data });
win.add(tableview);

function checkIndex(name, expected) {
    var actual = tableview.getIndexByName(name);
    Ti.API.info(name + "'s Index: " + actual);
    if (actual != expected) {
        alert(name + ' has an inaccurate index! expected: ' + expected + ', actual: ' + actual);
    }
}

setTimeout(function() {
    tableview.insertRowBefore(tableview.getIndexByName('C'), { title: 'B', name: 'B' });

    checkIndex('A', 0);
    checkIndex('B', 1);
    checkIndex('C', 2);
}, 1000);

Expected Behavior

Calling "insertRowBefore" a row should insert the row before the specified row. It should _not_ insert the row two rows before the specified row.

Comments

  1. Stephen Tramer 2011-04-15

    This is expected behavior.

  2. Andrew Kulinich 2011-06-13

    In this case following code behaves the same:
       tableview.insertRowBefore(0, { title: '0' });
       tableview.insertRowBefore(1, { title: '1' });
       
    It insert both lines before the first record. What is worse - it is impossible to insert row before last row. So as a developer I expect that following two lines must behave the same for i > 0:
       tableview.insertRowBefore(i, { title: '0' });
       tableview.insertRowAfter(i-1, { title: '0' });
       
    As for me this is a bug and should be fixed
  3. Dawson Toth 2011-07-14

    Updated ticket for better formatting and clarity of purpose.
  4. Sabil Rahim 2011-07-27

    pull # 298 pending
  5. Natalie Huynh 2011-08-25

    Tested with 1.8.0.v20110819142548 iPhone 4.3.4 iPad2 4.3.2 Motorola Xoom 3.2 Nexus One 2.2.2

JSON Source