1- import React , { useMemo , useState } from 'react' ;
1+ import React , { useMemo , useRef , useState } from 'react' ;
22import Header from './Header' ;
33import { Checkbox , Col , Empty , Row } from 'antd' ;
44import { CheckOutlined } from '@ant-design/icons' ;
@@ -22,7 +22,7 @@ const TableView = p => {
2222 p
2323 ) ;
2424 const { className, dataSource, columns, rowKey, rowSelection, valueIsEmpty, emptyIsPlaceholder, placeholder, empty, onRowSelect, render, ...others } = props ;
25-
25+ const dataSourceMapRef = useRef ( new Map ( ) ) ;
2626 const defaultSpan = useMemo ( ( ) => {
2727 const assignedSpan = columns . reduce ( ( a , b ) => {
2828 return a + ( b . span || 0 ) ;
@@ -35,9 +35,11 @@ const TableView = p => {
3535 const header = < Header { ...props } defaultSpan = { defaultSpan } colsSize = { colsSize } setColsSize = { setColsSize } /> ;
3636
3737 const renderBody = dataSource => {
38+ const getId = item => get ( item , typeof rowKey === 'function' ? rowKey ( item ) : rowKey ) ;
3839 return dataSource && dataSource . length > 0 ? (
3940 dataSource . map ( item => {
40- const id = get ( item , typeof rowKey === 'function' ? rowKey ( item ) : rowKey ) ;
41+ const id = getId ( item ) ;
42+ dataSourceMapRef . current . set ( id , item ) ;
4143 const isChecked = rowSelection ?. selectedRowKeys && rowSelection . selectedRowKeys . indexOf ( id ) > - 1 ;
4244 return (
4345 < Row
@@ -64,16 +66,23 @@ const TableView = p => {
6466 if ( rowSelection . type === 'checkbox' ) {
6567 const selectedRowKeys = ( rowSelection . selectedRowKeys || [ ] ) . slice ( 0 ) ;
6668 isChecked ? selectedRowKeys . splice ( rowSelection . selectedRowKeys . indexOf ( id ) , 1 ) : selectedRowKeys . push ( id ) ;
67- rowSelection . onChange ( selectedRowKeys ) ;
69+ rowSelection . onChange (
70+ selectedRowKeys ,
71+ selectedRowKeys . map ( id => dataSourceMapRef . current . get ( id ) )
72+ ) ;
6873 } else {
69- rowSelection . onChange ( rowSelection . selectedRowKeys . length && rowSelection . selectedRowKeys [ 0 ] === id ? [ ] : [ id ] ) ;
74+ const selectedRowKeys = rowSelection . selectedRowKeys . length && rowSelection . selectedRowKeys [ 0 ] === id ? [ ] : [ id ] ;
75+ rowSelection . onChange (
76+ selectedRowKeys ,
77+ selectedRowKeys . map ( id => dataSourceMapRef . current . get ( id ) )
78+ ) ;
7079 }
7180 } }
7281 >
7382 { rowSelection && rowSelection . type === 'checkbox' && (
7483 < Col className = { classnames ( style [ 'col' ] , 'info-page-table-col' ) } >
7584 < span className = { classnames ( style [ 'col-content' ] , 'info-page-table-col-content' ) } >
76- < Checkbox disabled = { item . disabled || rowSelection . isSelectedAll } checked = { rowSelection . isSelectedAll || isChecked } />
85+ < Checkbox disabled = { item . disabled || rowSelection . isSelectedAll } checked = { ( rowSelection . isSelectedAll && ! item . disabled ) || isChecked } />
7786 </ span >
7887 </ Col >
7988 ) }
@@ -177,5 +186,5 @@ const TableView = p => {
177186 </ div >
178187 ) ;
179188} ;
180-
189+ TableView . Header = Header ;
181190export default TableView ;
0 commit comments