Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-846] iOS: Dynamically setting row header (or removing) in table view = not work

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2017-06-07T22:28:05.000+0000
Affected Version/sRelease 1.5.0
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterNolan Wright
AssigneeIngo Muschenetz
Created2011-04-15T02:37:45.000+0000
Updated2017-06-07T22:28:05.000+0000

Description

from premium ticket:

http://helpdesk.appcelerator.net/tickets/1467">http://helpdesk.appcelerator.net/tickets/1467

code:

var data = [];
var win = Ti.UI.createWindow();
// Add filler data. // sort1 = index for this row if sorted by row number // sort2 = index for this row if reverse sorted by row number

for(var i = 0; i < 100; i++)
{

data.push({title:'Row '+i, sort1:i, sort2:(99 - i)});

}

// Add headers for default view based on first digit of row number.

var prev = -1;

for(i = 0; i < data.length; i++)
{

var v = Math.floor(parseInt(data[i].sort1, 10) / 10);

if(v != prev)
{
    prev = v;
    data[i].header = ''+v;
}

}

// Create table view.

var tableView = Ti.UI.createTableView({data:data, top:50,height:300});
win.add(tableView);

// Create button to swap between sorted data sets.

var b = Ti.UI.createButton({title:'Sort',top:10,height:30,width:300});
b.addEventListener('click', function(e)
{

sortData(tableView);

}); win.add(b);

// Swap between data sets for specified tableView.

function sortData(tv)
{

var newdata = [];
var sections = tv.data;

// Retrieve current data set.

for(var i = 0; i < sections.length; i++)
{
    var section = sections[i];

    for(var j = 0; j < section.rowCount; j++)
    {
        var row = section.rows[j];

        // Insert old row at the correct sorted position in the new array.
        newdata[row.sort2] = row;

        // Delete any existing header for this row so we don't munge headers from both data sets.
        delete newdata[row.sort2].header;
    }
}

// Add headers for newdata based on first digit of sort2.
var prev = -1;

for(i = 0; i < newdata.length; i++)
{
    var v = Math.floor(parseInt(newdata[i].sort2, 10) / 10);

    if(v != prev)
    {
        prev = v;
        newdata[i].header = ''+v;
    }
}

// Update tableView with newdata.
tv.setData(newdata);

}

win.open();

Comments

  1. Thomas Huelbert 2011-04-15

    valid, needs testcase

  2. Vikramjeet Singh 2011-08-04

    Bug Scrub: Valid. No test Case exists Note: Row header does not change dynamically after sorting the rows in a reverse order. Tested On: Mac OSX Lion TiMob Version: 1.7.2 TiStud Version: 1.0.2 Devices used: iPhone 4.3.4
  3. Lee Morris 2017-06-07

    Closing ticket due to time passed and lack of work.

JSON Source