Skip to content

Commit

Permalink
Refactor #1832 - For TreeTable
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Mar 1, 2021
1 parent 287502a commit b6c7a22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/components/treetable/TreeTableBody.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TreeTableRow } from './TreeTableRow';
import { TreeTableRow } from './TreeTableRow';

export class TreeTableBody extends Component {

Expand Down Expand Up @@ -60,10 +60,10 @@ export class TreeTableBody extends Component {
onContextMenu: PropTypes.func
}

createRow(node) {
createRow(node, index) {
return (
<TreeTableRow key={node.key||JSON.stringify(node.data)} level={0}
node={node} columns={this.props.columns} expandedKeys={this.props.expandedKeys}
<TreeTableRow key={node.key||JSON.stringify(node.data)} level={0} rowIndex={index}
node={node} columns={this.props.columns} expandedKeys={this.props.expandedKeys}
onToggle={this.props.onToggle} onExpand={this.props.onExpand} onCollapse={this.props.onCollapse}
selectionMode={this.props.selectionMode} selectionKeys={this.props.selectionKeys} onSelectionChange={this.props.onSelectionChange}
metaKeySelection={this.props.metaKeySelection} onRowClick={this.props.onRowClick} onSelect={this.props.onSelect} onUnselect={this.props.onUnselect}
Expand Down Expand Up @@ -91,8 +91,8 @@ export class TreeTableBody extends Component {
return rows;
}
else {
return this.props.value.map(node => this.createRow(node));
}
return this.props.value.map((node, index) => this.createRow(node, index));
}
}

renderEmptyMessage() {
Expand All @@ -118,4 +118,4 @@ export class TreeTableBody extends Component {
</tbody>
);
}
}
}
6 changes: 3 additions & 3 deletions src/components/treetable/TreeTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export class TreeTableRow extends Component {
}

return (
<TreeTableBodyCell key={column.props.columnKey||column.props.field} {...column.props} node={this.props.node}>
<TreeTableBodyCell key={column.props.columnKey||column.props.field} {...column.props} node={this.props.node} rowIndex={this.props.rowIndex}>
{toggler}
{checkbox}
</TreeTableBodyCell>
Expand All @@ -510,9 +510,9 @@ export class TreeTableRow extends Component {

renderChildren() {
if (this.isExpanded() && this.props.node.children) {
return this.props.node.children.map(childNode => {
return this.props.node.children.map((childNode, index) => {
return (
<TreeTableRow key={childNode.key||JSON.stringify(childNode.data)} level={this.props.level + 1}
<TreeTableRow key={childNode.key||JSON.stringify(childNode.data)} level={this.props.level + 1} rowIndex={this.props.rowIndex + '_' + index}
node={childNode} columns={this.props.columns} expandedKeys={this.props.expandedKeys}
onToggle={this.props.onToggle} onExpand={this.props.onExpand} onCollapse={this.props.onCollapse}
selectionMode={this.props.selectionMode} selectionKeys={this.props.selectionKeys} onSelectionChange={this.props.onSelectionChange}
Expand Down

0 comments on commit b6c7a22

Please sign in to comment.