Skip to content

Commit bf687d4

Browse files
authored
Merge pull request #60 from NadavShaar/removing-key-indexes
Keys update.
2 parents 8814c37 + 32dcc76 commit bf687d4

4 files changed

Lines changed: 28 additions & 29 deletions

File tree

src/components/ColumnVisibility.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ColumnVisibility = ({
2121
buttonChildren={columnVisibilityIcon}
2222
popoverChildren={
2323
columns.filter(column => column.label).map((column, idx) => (
24-
<div key={idx} className='rgt-clickable rgt-columns-manager-popover-row'>
24+
<div key={column.id} className='rgt-clickable rgt-columns-manager-popover-row'>
2525
<label
2626
htmlFor={`checkbox-${idx}`}
2727
title={column.label}

src/components/PageSize.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const PageSize = ({
2323
value={value}
2424
onChange={event => { onChange(event.target.value);}}
2525
>
26-
{ options.map((option, idx) => <option key={idx} value={option}>{option}</option>) }
26+
{ options.map((option, idx) => <option key={option} value={option}>{option}</option>) }
2727
</select>
2828
</div>
2929
)

src/components/Row.jsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ const Row = ({
1818

1919
if (isVirtualScroll) {
2020
if (index === 'virtual-start') {
21-
return visibleColumns.map((visibleColumn, colIndex) => (
22-
<div key={index + colIndex} style={{ minHeight: virtualItems[0]?.start }} />
23-
));
21+
return visibleColumns.map(visibleColumn =>
22+
<div key={`${index}-${visibleColumn.id}`} style={{ minHeight: virtualItems[0]?.start }} />
23+
);
2424
}
2525
if (index === 'virtual-end') {
26-
return visibleColumns.map((visibleColumn, colIndex) => (
27-
<div key={index + colIndex} style={{ minHeight: totalSize - virtualItems[virtualItems.length - 1]?.end || 0 }} />
28-
));
26+
return visibleColumns.map(visibleColumn =>
27+
<div key={`${index}-${visibleColumn.id}`} style={{ minHeight: totalSize - virtualItems[virtualItems.length - 1]?.end || 0 }} />
28+
);
2929
}
3030
}
3131

@@ -34,24 +34,22 @@ const Row = ({
3434
let disableSelection = !data || !getIsRowSelectable(data);
3535
let isSelected = !!data && !!(selectedRowsIds.find(selectedRowId => selectedRowId === rowId));
3636
let isEdit = !!data && editRow?.[rowIdField] === rowId && !!getIsRowEditable(data);
37-
38-
return visibleColumns.map((visibleColumn, colIndex) => {
39-
return (
40-
<CellContainer
41-
key={rowIndex+colIndex}
42-
rowId={rowId}
43-
data={rowId && (editRow?.[rowIdField] === rowId) ? editRow : data}
44-
rowIndex={rowIndex}
45-
colIndex={colIndex}
46-
column={visibleColumn}
47-
isSelected={isSelected}
48-
isEdit={isEdit}
49-
disableSelection={disableSelection}
50-
forwardRef={colIndex === 0 ? measureRef : undefined}
51-
tableManager={tableManager}
52-
/>
53-
)
54-
})
37+
38+
return visibleColumns.map((visibleColumn, colIndex) =>
39+
<CellContainer
40+
key={`${visibleColumn.id}-${rowId}`}
41+
rowId={rowId}
42+
data={rowId && (editRow?.[rowIdField] === rowId) ? editRow : data}
43+
rowIndex={rowIndex}
44+
colIndex={colIndex}
45+
column={visibleColumn}
46+
isSelected={isSelected}
47+
isEdit={isEdit}
48+
disableSelection={disableSelection}
49+
forwardRef={colIndex === 0 ? measureRef : undefined}
50+
tableManager={tableManager}
51+
/>
52+
)
5553
};
5654

5755
export default Row;

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const GridTable = props => {
1616
isLoading,
1717
config: {
1818
isVirtualScroll,
19+
rowIdField,
1920
components: { Header, Footer, Loader, NoResults, DragHandle },
2021
},
2122
refs: { rgtRef, tableRef },
@@ -55,8 +56,8 @@ const GridTable = props => {
5556
}}
5657
>
5758
{
58-
visibleColumns.map((cd, idx) => (
59-
<HeaderCellContainer key={idx} index={idx} column={cd} tableManager={tableManager}/>
59+
visibleColumns.map((visibleColumn, idx) => (
60+
<HeaderCellContainer key={visibleColumn.id} index={idx} column={visibleColumn} tableManager={tableManager}/>
6061
))
6162
}
6263
{
@@ -68,7 +69,7 @@ const GridTable = props => {
6869
<Row key={'virtual-end'} index={'virtual-end'} tableManager={tableManager} />
6970
]
7071
:
71-
pageRows.map((rowData, index) => <Row key={index} index={index} data={rowData} tableManager={tableManager} />)
72+
pageRows.map((rowData, index) => <Row key={rowData?.[rowIdField]} index={index} data={rowData} tableManager={tableManager} />)
7273
:
7374
<div className='rgt-container-overlay'>
7475
{

0 commit comments

Comments
 (0)