Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12606] Ti.UI.DashboardView.setData() appends to dataset, it doesn't actually reset it

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-03-18T18:58:38.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.1.0, 2013 Sprint 06 API, 2013 Sprint 06
ComponentsiOS
Labelsios, module_dashboardview, qe-testadded
ReporterTony Lukasavage
AssigneeSabil Rahim
Created2013-02-06T17:32:03.000+0000
Updated2013-09-27T09:30:48.000+0000

Description

problem

When calling Ti.UI.DashboardView.setData(), one would expect, like with Ti.UI.TableView, that the data given to the function call would reset the DashboardView. The problem is that instead of reseting it with the given array of DashboardItems, it instead appends the array to the existing list of data. This essentially leaves developers with no programmatic way to reset or remove items from the DashboardView. The remove() function operates on Views added to the Dashboard's view hierarchy, not its collection of items and will not work on DashboardItems. This creates an issue with applications that contain a data model that describes the items. This existed originally in this Q&A question (unresolved): http://developer.appcelerator.com/question/92191/bug-in-dashboardview-when-adding-view-items Additionally, this is a problem for Alloy when it comes to data binding. Developers in Alloy should be able to define their DashboardItems as a collection and use binding to control the appearance of the DashboardView. As of now this is not possible and will cause unexpected behavior.

test case

Create a new Titanium mobile project

Run the following code for iOS (iphone sim is what I tested):

var win = Ti.UI.createWindow({
	backgroundColor: '#fff'
});

var data = [];
data.push(Ti.UI.createDashboardItem({
	image: 'KS_nav_ui.png',
	badge: 10,
	label: 'test1',
	customId: 'id1'	
}));
data.push(Ti.UI.createDashboardItem({
	image: 'KS_nav_views.png',
	badge: 99,
	label: 'test2',
	customId: 'id2'	
}));

var dash = Ti.UI.createDashboardView({
	wobble: true,
	data: data
});
dash.addEventListener('click', function(e) {
	for (var i = 0; i < data.length; i++) {
		if (data[i].customId === e.item.customId) {
			data[i].badge = 0;	
		} 
	}
	dash.data = data; // appends data, does not reset it
	// dash.setData(data); // this doesn't work either
});

win.add(dash);
win.open();

Click a DashboardItem. It should set the badge to zero. It instead appends all the items again, having unexpected behavior with its re-rendering as well as with the resulting badge numbers.

Comments

  1. Sabil Rahim 2013-03-14

    PR https://github.com/appcelerator/titanium_mobile/pull/3964
  2. Blain Hamon 2013-03-18

    Pull merged.
  3. Anshu Mittal 2013-03-21

    Tested with: SDK:3.1.0.v20130319222852 Studio: 3.0.2.201302191606 Device: iPad2(v 5.1)

JSON Source