Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6688] Android: Tableview insertRowAfter/Before works with first section only

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2021-03-24T19:31:06.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterAhmed Mohamed
AssigneeGary Mathews
Created2021-03-23T15:25:31.000+0000
Updated2021-03-24T22:18:13.000+0000

Description

When trying to insert a row in any section below the first section it doesn't work on Android but it works on iOS as it should be. So insertRowAfter / insertRowBefore doesn't work.
var win = Ti.UI.createWindow();

var sectionOne = Ti.UI.createTableViewSection({
    headerTitle: 'Section One'
});
sectionOne.add(Ti.UI.createTableViewRow({
    title: 'Row 1'
}));
sectionOne.add(Ti.UI.createTableViewRow({
    title: 'Row 2'
}));

var sectionTwo = Ti.UI.createTableViewSection({
    headerTitle: 'Section Two'
});
sectionTwo.add(Ti.UI.createTableViewRow({
    title: 'Row 3'
}));
sectionTwo.add(Ti.UI.createTableViewRow({
    title: 'Row 4'
}));

var table = Ti.UI.createTableView({
    data: [sectionOne, sectionTwo]
});

var button = Ti.UI.createButton({
    title: "Add Row",
    bottom: 16
});
button.addEventListener('click', () => {
    var row = Ti.UI.createTableViewRow({
        title: "New Row"
    });

    table.insertRowAfter(2, row, {
        animated: true
    });
});

win.add(table);
win.add(button);
win.open();

Comments

  1. Gary Mathews 2021-03-24

    This has been fixed in the latest master and 10_0_X branches. *TEST CASE*
       const win = Ti.UI.createWindow();
       
       function createSection(header, rows) {
       	const section = Ti.UI.createTableViewSection({
       		headerTitle: header
       	});
       
       	for (let i = 0; i < rows; i++) {
       		section.add(
       			Ti.UI.createTableViewRow({ title: Row #${i} })
       		);
       	}
       
       	return section;
       }
       
       
       const table = Ti.UI.createTableView({
           data: [
           	createSection('Section #0', 3),
           	createSection('Section #1', 3),
           	createSection('Section #2', 3),
       	]
       });
       
       table.addEventListener('click', e => {
       	table.insertRowAfter(
       		e.index,
       		Ti.UI.createTableViewRow({ title: New After Row #${e.index} })
       	);
       	table.insertRowBefore(
       		e.index,
       		Ti.UI.createTableViewRow({ title: New Before Row #${e.index} })
       	);
       });
       
       win.add(table);
       win.open();
       
  2. Ahmed Mohamed 2021-03-24

    I haven't seen any related ticket but after build 9_3_x I confirm this issue has been resolved. Thanks

JSON Source