fix focus error. fix table setData error. fixes #160.

This commit is contained in:
Christopher Jeffrey 2015-07-30 17:55:40 -07:00
parent ad3a5ae7f9
commit 22469380e2
5 changed files with 28 additions and 3 deletions

View File

@ -65,6 +65,10 @@ function ListTable(options) {
this.setData(options.rows || options.data);
this.on('attach', function() {
self.setData(self.rows);
});
this.on('resize', function() {
var selected = self.selected;
self.setData(self.rows);
@ -84,7 +88,9 @@ ListTable.prototype.setData = function(rows) {
var self = this
, align = this.__align;
this.clearPos();
if (this.visible && this.lpos) {
this.clearPos();
}
this.clearItems();
@ -92,6 +98,8 @@ ListTable.prototype.setData = function(rows) {
this._calculateMaxes();
if (!this._maxes) return;
this.addItem('');
this.rows.forEach(function(row, i) {

View File

@ -1623,6 +1623,8 @@ Screen.prototype._focus = function(self, old) {
if (el.scrollable) break;
}
if (el && el.detached) return;
// If we're in a scrollable element,
// automatically scroll to the focused element.
if (el) {

View File

@ -44,6 +44,11 @@ function Table(options) {
this.setData(options.rows || options.data);
this.on('attach', function() {
self.setContent('');
self.setData(self.rows);
});
this.on('resize', function() {
self.setContent('');
self.setData(self.rows);
@ -59,6 +64,10 @@ Table.prototype._calculateMaxes = function() {
var self = this;
var maxes = [];
if (this.detached) return;
this.rows = this.rows || [];
this.rows.forEach(function(row) {
row.forEach(function(cell, i) {
var clen = self.strWidth(cell);
@ -110,6 +119,8 @@ Table.prototype.setData = function(rows) {
this._calculateMaxes();
if (!this._maxes) return;
this.rows.forEach(function(row, i) {
var isHeader = i === 0;
var isFooter = i === self.rows.length - 1;

View File

@ -30,7 +30,7 @@ var box = blessed.box({
*/
var table = blessed.listtable({
parent: screen,
//parent: screen,
top: 'center',
left: 'center',
data: null,
@ -89,6 +89,9 @@ screen.key('q', function() {
table.focus();
table.setData(data2);
screen.append(table);
screen.render();
setTimeout(function() {

View File

@ -12,7 +12,7 @@ var DU = '杜';
var JUAN = '鹃';
var table = blessed.table({
parent: screen,
//parent: screen,
top: 'center',
left: 'center',
data: null,
@ -62,6 +62,7 @@ screen.key('q', function() {
});
table.setData(data2);
screen.append(table);
screen.render();
setTimeout(function() {