Skip to content

Commit

Permalink
Merge pull request #2681 from bryan-m-hughes/timob-10325
Browse files Browse the repository at this point in the history
[TIMOB-10325] Implemented support for accessing sections in TableView
  • Loading branch information
cb1kenobi committed Aug 9, 2012
2 parents 7f22439 + 27b631a commit 5c743ca
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 11 deletions.
115 changes: 113 additions & 2 deletions apidoc/Titanium/UI/TableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,28 @@ methods:
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true

- name: appendSection
summary: Appends one or more sections to the table.
description: |
Appends a single section or an array of sections to the end of the table.
Each row can be passed as a [TableViewSection](Titanium.UI.TableViewSection) object, or as
dictionary specifying the properties for a table section, in which case this `TableView` will
create `TableViewSection` objects as needed.
On iOS, the row(s) can be inserted with animation by specifying a `properties` parameter.
parameters:
- name: section
summary: Section or section to add to the table.
type: [Titanium.UI.TableViewSection, Dictionary<Titanium.UI.TableViewSection>, Array<Titanium.UI.TableViewSection>, Array<Dictionary<Titanium.UI.TableViewSection>>]

- name: animation
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true
since: 2.2.0
platforms: [mobileweb]

- name: deleteRow
summary: Deletes an existing row.
Expand All @@ -632,6 +654,22 @@ methods:
type: TableViewAnimationProperties
optional: true

- name: deleteSection
summary: Deletes an existing section.
description: |
On iOS, the section can be deleted with animation by specifying a `properties` parameter.
parameters:
- name: section
summary: Index of the section to delete.
type: Number

- name: animation
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true
since: 2.2.0
platforms: [mobileweb]

- name: deselectRow
summary: Programmatically deselects a row.
parameters:
Expand Down Expand Up @@ -661,6 +699,30 @@ methods:
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true

- name: insertSectionAfter
summary: Inserts a section after another section.
description: |
Each section can be passed as a [TableViewSection](Titanium.UI.TableViewSection) object, or as
dictionary specifying the properties for a table section, in which case this `TableView` will
create `TableViewSection` objects as needed.
On iOS, the section(s) may be inserted with animation by setting the `animation` parameter.
parameters:
- name: index
summary: Index of the section to insert after.
type: Number

- name: section
summary: section to insert.
type: [Titanium.UI.TableViewSection, Dictionary<Titanium.UI.TableViewSection>]

- name: animation
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true
since: 2.2.0
platforms: [mobileweb]

- name: insertRowBefore
summary: Inserts a row before another row.
Expand All @@ -683,6 +745,30 @@ methods:
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true

- name: insertSectionBefore
summary: Inserts a section before another section.
description: |
Each section can be passed as a [TableViewSection](Titanium.UI.TableViewSection) object, or as
dictionary specifying the properties for a table section, in which case this `TableViewSection` will
create `TableViewSection` objects as needed.
On iOS, the section(s) may be inserted with animation by setting the `animation` parameter.
parameters:
- name: index
summary: Index of the section to insert before.
type: Number

- name: section
summary: section to insert.
type: [Titanium.UI.TableViewSection, Dictionary<Titanium.UI.TableViewSection>]

- name: animation
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
optional: true
since: 2.2.0
platforms: [mobileweb]

- name: scrollToIndex
summary: Scrolls the table view to ensure that the specified row is on screen.
Expand Down Expand Up @@ -804,6 +890,23 @@ methods:
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties

- name: updateSection
summary: Updates an existing section, optionally with animation
parameters:
- name: index
summary: Index of the section to update.
type: Number

- name: section
summary: section data to update.
type: Titanium.UI.TableViewSection

- name: animation
summary: Animation properties. (iOS only.)
type: TableViewAnimationProperties
since: 2.2.0
platforms: [mobileweb]

properties:
- name: allowsSelection
summary: Determines whether this table's rows can be selected.
Expand Down Expand Up @@ -1016,11 +1119,19 @@ properties:
type: Boolean
default: false (search field visible)
platforms: [iphone, ipad]

- name: sectionCount
summary: Number of sections in this table view.
type: Number
permission: read-only
since: 2.2.0
platforms: [iphone, ipad, mobileweb]

- name: section
- name: sections
summary: Sections of this table.
type: Array<Titanium.UI.TableViewSection>
platforms: [iphone, ipad]
since: 2.2.0
platforms: [iphone, ipad, mobileweb]

- name: separatorColor
summary: Separator line color between rows, as a color name or hex triplet.
Expand Down
85 changes: 76 additions & 9 deletions mobileweb/titanium/Ti/UI/TableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",

constructor: function(args) {

var self = this,
scrollbarTimeout,
var scrollbarTimeout,
contentContainer;
self._initKineticScrollView(contentContainer = UI.createView({
this._initKineticScrollView(contentContainer = UI.createView({
width: UI.INHERIT,
height: UI.SIZE,
left: 0,
top: 0,
layout: UI._LAYOUT_CONSTRAINING_VERTICAL
}), "vertical", "vertical", 1);

contentContainer._add(self._header = UI.createView({
contentContainer._add(this._header = UI.createView({
height: UI.SIZE,
width: UI.INHERIT,
layout: UI._LAYOUT_CONSTRAINING_VERTICAL
}));
contentContainer._add(self._sections = UI.createView({
contentContainer._add(this._sections = UI.createView({
height: UI.SIZE,
width: UI.INHERIT,
layout: UI._LAYOUT_CONSTRAINING_VERTICAL
}));
contentContainer._add(self._footer = UI.createView({
contentContainer._add(this._footer = UI.createView({
height: UI.SIZE,
width: UI.INHERIT,
layout: UI._LAYOUT_CONSTRAINING_VERTICAL
}));

self.data = [];
this.data = [];
this.constants.__values__.sections = [];
},

_handleMouseWheel: function() {
Expand Down Expand Up @@ -233,15 +233,16 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",

_removeRow: function(index) {
var location = this._calculateLocation(index);
this._unpublish(location.section._rows._children[2 * location.localIndex + 1]);
if (location) {
this._unpublish(location.section._rows._children[2 * location.localIndex + 1]);
location.section._removeAt(location.localIndex);
}
},

appendRow: function(value) {
if (!this._currentSection) {
this._sections._add(this._currentSection = UI.createTableViewSection({_tableView: this}));
this.sections.push(this._currentSection);
this._sections._add(this._createSeparator());
this.data.push(this._currentSection);
}
Expand Down Expand Up @@ -277,6 +278,67 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",
this._setTranslation(0,-top);
},

sectionAtIndex: function(index) {
return this.sections[index];
},

_insertSection: function(sections, index) {
!is(sections,"Array") && (sections = [sections]);
var i = 0,
len = sections.length;
for(; i < len; i++) {
if (!isDef(sections[i].declaredClass) || sections[i].declaredClass != "Ti.UI.TableViewSection") {
sections[i] = UI.createTableViewSection(sections[i]);
}
this._sections._insertAt(sections[i], index + i);
if (index === len) {
this.sections.push(sections[i]);
} else {
this.sections.splice(index,0,sections[i]);
}
}
this._refreshSections();
},

_removeSection: function(index) {
this._sections._remove(this.sections[index]);
this.sections.splice(index,1);
},

appendSection: function(section) {
this._insertSection(section, this.sections.length);
},

deleteSection: function(section) {
var index = this.sections.indexOf(section);
if (~index) {
this._sections._remove(section);
this.sections.splice(index,1);
}
},

insertSectionBefore: function(index, section) {
this._insertSection(section, index);
},

insertSectionAfter: function(index, section) {
this._insertSection(section, index + 1);
},

updateSection: function(index, section) {
this._removeSection(index);
this._insertSection(section, index);
},

constants: {
sectionCount: {
get: function() {
return this.sections.length;
}
},
sections: void 0,
},

properties: {
data: {
set: function(value) {
Expand All @@ -286,6 +348,7 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",

// Remove all of the previous sections
this._sections._removeAllChildren();
this.constants.__values__.sections = [];
this._currentSection = void 0;

// Convert any object literals to TableViewRow instances
Expand All @@ -300,7 +363,9 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",
if (value[i].declaredClass === "Ti.UI.TableViewRow") {
// Check if we need a default section
if (!this._currentSection) {
this._sections._add(this._currentSection = UI.createTableViewSection({_tableView: this}));
this.appendSection(UI.createTableViewSection({_tableView: this}));
this._sections._add();
this.sections.push(this._currentSection);
this._sections._add(this._createSeparator());
retval.push(this._currentSection);
}
Expand All @@ -309,6 +374,7 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",
value[i]._tableView = this;
this._sections._add(this._currentSection = value[i]);
this._sections._add(this._createSeparator());
this.sections.push(this._currentSection);
retval.push(this._currentSection);
}
this._publish(value[i]);
Expand Down Expand Up @@ -369,6 +435,7 @@ define(["Ti/_/declare", "Ti/_/UI/KineticScrollView", "Ti/_/style", "Ti/_/lang",
post: "_refreshSections",
value: "50px"
},

separatorColor: {
post: "_refreshSections",
value: "lightGrey"
Expand Down

0 comments on commit 5c743ca

Please sign in to comment.