selecting rows from outside
Summary: Allows to set the selected rows of a table using the `highlightedRows` property. Reviewed By: passy Differential Revision: D9850597 fbshipit-source-id: 62239192113f43ac257d7328b21b386b584a7cfb
This commit is contained in:
committed by
Facebook Github Bot
parent
3f128bcd50
commit
26dd94f072
@@ -102,6 +102,10 @@ export type ManagedTableProps = {|
|
||||
* Whether to hide the column names at the top of the table.
|
||||
*/
|
||||
hideHeader?: boolean,
|
||||
/**
|
||||
* Rows that are highlighted initially.
|
||||
*/
|
||||
highlightedRows?: Set<string>,
|
||||
|};
|
||||
|
||||
type ManagedTableState = {|
|
||||
@@ -141,7 +145,7 @@ class ManagedTable extends React.Component<
|
||||
this.props.columnOrder ||
|
||||
Object.keys(this.props.columns).map(key => ({key, visible: true})),
|
||||
columnSizes: this.props.columnSizes || {},
|
||||
highlightedRows: new Set(),
|
||||
highlightedRows: this.props.highlightedRows || new Set(),
|
||||
sortOrder: null,
|
||||
shouldScrollToBottom: Boolean(this.props.stickyBottom),
|
||||
};
|
||||
@@ -173,8 +177,26 @@ class ManagedTable extends React.Component<
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
if (this.props.highlightedRows !== nextProps.highlightedRows) {
|
||||
this.setState({highlightedRows: nextProps.highlightedRows});
|
||||
const {current} = this.tableRef;
|
||||
const {highlightedRows} = nextProps;
|
||||
if (current && highlightedRows && highlightedRows.size > 0) {
|
||||
const index = nextProps.rows.findIndex(
|
||||
({key}) => key === Array.from(highlightedRows)[0],
|
||||
);
|
||||
current.scrollToItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
// if columnOrder has changed
|
||||
if (nextProps.columnOrder !== this.props.columnOrder) {
|
||||
if (
|
||||
nextProps.columnOrder !== this.props.columnOrder &&
|
||||
this.tableRef &&
|
||||
this.tableRef.current
|
||||
) {
|
||||
this.tableRef.current.resetAfterIndex(0);
|
||||
this.setState({
|
||||
columnOrder: nextProps.columnOrder,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user