Skip to content

Commit 90196c2

Browse files
authored
add getDOMNode method (#73)
* add getDOMNode method * update * update
1 parent eb558bc commit 90196c2

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## NEXT VERSION
44

55
- chore: remove the use of `Object.values`
6+
- feat: add `getColumnManager` and `getDOMNode` methods
67

78
## v1.6.5 (2019-07-11)
89

src/BaseTable.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class BaseTable extends React.PureComponent {
6262
};
6363
this.columnManager = new ColumnManager(columns || normalizeColumns(children), props.fixed);
6464

65+
this._setContainerRef = this._setContainerRef.bind(this);
6566
this._setMainTableRef = this._setMainTableRef.bind(this);
6667
this._setLeftTableRef = this._setLeftTableRef.bind(this);
6768
this._setRightTableRef = this._setRightTableRef.bind(this);
@@ -102,6 +103,20 @@ class BaseTable extends React.PureComponent {
102103
this._scrollbarPresenceChanged = false;
103104
}
104105

106+
/**
107+
* Get the DOM node of the table
108+
*/
109+
getDOMNode() {
110+
return this.tableNode;
111+
}
112+
113+
/**
114+
* Get the column manager
115+
*/
116+
getColumnManager() {
117+
return this.columnManager;
118+
}
119+
105120
/**
106121
* Get the expanded state, fallback to normal state if not expandable.
107122
*/
@@ -182,23 +197,21 @@ class BaseTable extends React.PureComponent {
182197
* Scroll to the specified row.
183198
* By default, the table will scroll as little as possible to ensure the row is visible.
184199
* You can control the alignment of the row though by specifying an align property. Acceptable values are:
185-
*
200+
*
186201
* - `auto` (default) - Scroll as little as possible to ensure the row is visible.
187-
* (If the row is already visible, it won't scroll at all.)
188-
* - `smart` - If the row is already visible, don't scroll at all. If it is less than one viewport away,
189-
* scroll as little as possible so that it becomes visible.
190-
* If it is more than one viewport away, scroll so that it is centered within the grid.
202+
* - `smart` - Same as `auto` if it is less than one viewport away, or it's the same as`center`.
191203
* - `center` - Center align the row within the table.
192-
* - `end` - Align the row to the bottom, right hand side of the table.
193-
* - `start` - Align the row to the top, left hand of the table.
204+
* - `end` - Align the row to the bottom side of the table.
205+
* - `start` - Align the row to the top side of the table.
194206
195-
* @param {number} rowIndex
196-
* @param {string} align
207+
* @param {number} rowIndex
208+
* @param {string} align
197209
*/
198210
scrollToRow(rowIndex = 0, align = 'auto') {
199211
this.table && this.table.scrollToRow(rowIndex, align);
200212
this.leftTable && this.leftTable.scrollToRow(rowIndex, align);
201213
this.rightTable && this.rightTable.scrollToRow(rowIndex, align);
214+
this.scrollToLeft(0);
202215
}
203216

204217
/**
@@ -605,7 +618,7 @@ class BaseTable extends React.PureComponent {
605618
[`${classPrefix}--disabled`]: disabled,
606619
});
607620
return (
608-
<div className={cls} style={containerStyle}>
621+
<div ref={this._setContainerRef} className={cls} style={containerStyle}>
609622
{this.renderFooter()}
610623
{this.renderMainTable()}
611624
{this.renderLeftTable()}
@@ -660,6 +673,10 @@ class BaseTable extends React.PureComponent {
660673
return `${this.props.classPrefix}__${className}`;
661674
}
662675

676+
_setContainerRef(ref) {
677+
this.tableNode = ref;
678+
}
679+
663680
_setMainTableRef(ref) {
664681
this.table = ref;
665682
}

website/src/utils/baseScope.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const noop = () => {}
4444
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
4545
const action = message => args => console.log(message, args)
4646

47-
const Table = props => <BaseTable width={700} height={400} {...props} />
47+
const Table = React.forwardRef((props, ref) => (
48+
<BaseTable ref={ref} width={700} height={400} {...props} />
49+
))
4850
Table.Column = Column
4951

5052
export default {

0 commit comments

Comments
 (0)