@@ -4,7 +4,7 @@ import { Checkbox, Col, Empty, Row } from 'antd';
44import { CheckOutlined } from '@ant-design/icons' ;
55import classnames from 'classnames' ;
66import get from 'lodash/get' ;
7- import formatView from '../formatView ' ;
7+ import computeColumnsValue , { computeDisplay , computeColumnsDisplay } from '../computeColumnsValue ' ;
88import { isEmpty } from '@kne/is-empty' ;
99import style from './style.module.scss' ;
1010
@@ -21,7 +21,7 @@ const TableView = p => {
2121 } ,
2222 p
2323 ) ;
24- const { className, dataSource, columns, rowKey, rowSelection, valueIsEmpty, emptyIsPlaceholder, placeholder, empty, onRowSelect, render, ...others } = props ;
24+ const { className, dataSource, columns, rowKey, rowSelection, valueIsEmpty, emptyIsPlaceholder, placeholder, empty, onRowSelect, render, context , sticky , ...others } = props ;
2525 const dataSourceMapRef = useRef ( new Map ( ) ) ;
2626 const defaultSpan = useMemo ( ( ) => {
2727 const assignedSpan = columns . reduce ( ( a , b ) => {
@@ -32,15 +32,16 @@ const TableView = p => {
3232 return Math . round ( Math . max ( 24 - assignedSpan , 0 ) / undistributedColCount ) ;
3333 } , [ columns ] ) ;
3434
35- const header = < Header { ...props } defaultSpan = { defaultSpan } colsSize = { colsSize } setColsSize = { setColsSize } /> ;
35+ const header = < Header { ...props } sticky = { sticky } defaultSpan = { defaultSpan } colsSize = { colsSize } setColsSize = { setColsSize } /> ;
3636
37- const renderBody = dataSource => {
37+ const renderBody = ( dataSource , context ) => {
3838 const getId = item => get ( item , typeof rowKey === 'function' ? rowKey ( item ) : rowKey ) ;
3939 return dataSource && dataSource . length > 0 ? (
4040 dataSource . map ( item => {
4141 const id = getId ( item ) ;
4242 dataSourceMapRef . current . set ( id , item ) ;
4343 const isChecked = rowSelection ?. selectedRowKeys && rowSelection . selectedRowKeys . indexOf ( id ) > - 1 ;
44+ const columnsValue = computeColumnsValue ( { columns, emptyIsPlaceholder, valueIsEmpty, removeEmpty : false , dataSource : item , placeholder, context } ) ;
4445 return (
4546 < Row
4647 wrap = { false }
@@ -88,50 +89,8 @@ const TableView = p => {
8889 ) }
8990 < Col flex = { 1 } >
9091 < Row className = { classnames ( 'info-page-table-row-content' ) } wrap = { false } >
91- { columns . map ( column => {
92+ { columnsValue . map ( column => {
9293 const { name, span } = column ;
93- const colItem = ( item => {
94- const itemValue =
95- typeof column . getValueOf === 'function'
96- ? column . getValueOf ( item , {
97- dataSource,
98- columns,
99- column,
100- target : item
101- } )
102- : get ( item , column . name ) ;
103-
104- const displayValue = ( value => {
105- if ( typeof column . format === 'function' ) {
106- return column . format ( value , {
107- dataSource,
108- columns,
109- column,
110- target : item
111- } ) ;
112- }
113- if ( typeof column . format === 'string' ) {
114- const formatValue = formatView ( value , column . format , {
115- dataSource,
116- columns,
117- column,
118- target : item
119- } ) ;
120- if ( formatValue ) {
121- return formatValue ;
122- }
123- }
124- return value ;
125- } ) ( itemValue ) ;
126-
127- const itemIsEmpty = ( column . valueIsEmpty || valueIsEmpty ) ( itemValue ) ;
128-
129- if ( ! ( column . hasOwnProperty ( 'emptyIsPlaceholder' ) ? column . emptyIsPlaceholder : emptyIsPlaceholder ) && itemIsEmpty ) {
130- return null ;
131- }
132- return Object . assign ( { } , column , { isEmpty : itemIsEmpty , value : displayValue } ) ;
133- } ) ( item ) ;
134-
13594 return (
13695 < Col
13796 key = { name }
@@ -143,26 +102,7 @@ const TableView = p => {
143102 } }
144103 className = { classnames ( style [ 'col' ] , 'info-page-table-col' ) }
145104 >
146- < span className = { style [ 'col-content' ] } >
147- { colItem . isEmpty
148- ? typeof colItem . renderPlaceholder === 'function'
149- ? colItem . renderPlaceholder ( {
150- column,
151- dataSource,
152- columns,
153- placeholder,
154- target : item
155- } )
156- : colItem . placeholder || placeholder
157- : typeof colItem . render === 'function'
158- ? colItem . render ( colItem . value , {
159- column,
160- columns,
161- dataSource,
162- target : item
163- } )
164- : colItem . value }
165- </ span >
105+ < span className = { style [ 'col-content' ] } > { computeDisplay ( { column, placeholder, dataSource : item , context } ) } </ span >
166106 </ Col >
167107 ) ;
168108 } ) }
@@ -182,7 +122,7 @@ const TableView = p => {
182122 return (
183123 < div { ...others } className = { classnames ( style [ 'table' ] , 'info-page-table' , className ) } >
184124 { header }
185- < div className = { classnames ( 'info-page-table-body' ) } > { renderBody ( dataSource ) } </ div >
125+ < div className = { classnames ( 'info-page-table-body' ) } > { renderBody ( dataSource , context ) } </ div >
186126 </ div >
187127 ) ;
188128} ;
0 commit comments