1
- import React , { useState , useRef , useMemo } from 'react' ;
1
+ import React , { useState , useEffect , useRef , useMemo , } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import classNames from 'classnames' ;
4
- import { tagPropType } from './Shared/helper.js' ;
4
+ import { tagPropType , mapToCssModules } from './Shared/helper.js' ;
5
5
import Slot from './Shared/Slot' ;
6
- import { CIcon } from '@coreui/icons-react ' ;
6
+ import CIcon from '../coreui-icons/CIcon ' ;
7
7
import CSpinner from './CSpinner' ;
8
8
import CPagination from './CPagination' ;
9
9
import style from './CDataTable.module.css' ;
@@ -26,6 +26,7 @@ const CDataTable = props=>{
26
26
captionSlot,
27
27
underTableSlot,
28
28
colNameSlot,
29
+ scopedSlots,
29
30
fields,
30
31
pagination,
31
32
activePage,
@@ -50,8 +51,9 @@ const CDataTable = props=>{
50
51
loading,
51
52
change,
52
53
onChange,
53
- //customContent,
54
- //...attributes
54
+ customContent,
55
+ sorterValue,
56
+ columnFilterValue
55
57
} = props ;
56
58
57
59
//Object.assign(style, cssModule)
@@ -101,7 +103,7 @@ const CDataTable = props=>{
101
103
const headerStyles = ( index ) => {
102
104
let style = { }
103
105
if ( isSortable ( index ) ) {
104
- style [ 'cursor' ] = 'pointer; ' ;
106
+ style [ 'cursor' ] = 'pointer' ;
105
107
}
106
108
if ( fields && fields [ index ] && fields [ index ] . _style ) {
107
109
let r = fields [ index ] . _style . split ( ':' ) ;
@@ -271,12 +273,10 @@ const CDataTable = props=>{
271
273
} , [ itemsPerPage ] ) ;
272
274
273
275
//sorterValue
274
- /*
275
276
useMemo ( ( ) => {
276
277
const asc = sorterValue . asc === false ? false : true ;
277
278
setSorterState ( Object . assign ( { } , { asc, column : sorterValue . column } ) ) ;
278
279
} , [ sorterValue ] ) ;
279
- */
280
280
281
281
//tableFilterValue
282
282
useMemo ( ( ) => {
@@ -285,11 +285,9 @@ const CDataTable = props=>{
285
285
} , [ tableFilterValue ] ) ;
286
286
287
287
//columnFilterValue
288
- /*
289
288
useMemo ( ( ) => {
290
289
setColumnFilterState ( Object . assign ( { } , columnFilterValue ) ) ;
291
290
} , [ columnFilterValue ] ) ;
292
- */
293
291
294
292
//items
295
293
useMemo ( ( ) => {
@@ -318,10 +316,17 @@ const CDataTable = props=>{
318
316
319
317
compData . firstRun = false ;
320
318
321
- let scopedSlots = { } ; //+
319
+ let paginationProps ;
320
+ if ( typeof pagination === 'object' )
321
+ paginationProps = { ...pagination }
322
+ else {
323
+ paginationProps = { }
324
+ }
325
+
326
+ console . log ( scopedSlots ) ;
322
327
323
328
return (
324
- < React . Fragment >
329
+ < >
325
330
< div ref = { innerRef } >
326
331
{
327
332
itemsPerPageSelect || tableFilter ?
@@ -343,7 +348,7 @@ const CDataTable = props=>{
343
348
{
344
349
itemsPerPageSelect ?
345
350
< div
346
- className = { 'col-sm-6 p-0' + ! tableFilter ? 'offset-sm-6' : '' }
351
+ className = { 'col-sm-6 p-0' + ( ! tableFilter ? 'offset-sm-6' : '' ) }
347
352
>
348
353
< div className = "form-inline justify-content-sm-end" >
349
354
< label className = "mr-2" > Items per page:</ label >
@@ -437,12 +442,12 @@ const CDataTable = props=>{
437
442
}
438
443
</ thead >
439
444
< tbody
440
- style = { clickableRows ? ' cursor:pointer;' : null }
445
+ style = { clickableRows ? { cursor : ' pointer' } : null }
441
446
className = "position-relative"
442
447
>
443
448
{ currentItems . map ( ( item , itemIndex ) => {
444
449
return (
445
- < React . Fragment >
450
+ < >
446
451
< tr
447
452
className = { classNames ( item . _classes ) }
448
453
tabIndex = { clickableRows ? 0 : null }
@@ -454,9 +459,7 @@ const CDataTable = props=>{
454
459
if ( scopedSlots [ colName ] )
455
460
return (
456
461
< Slot
457
- content = { colNameSlot }
458
- item = { item }
459
- index = { itemIndex + firstItemIndex }
462
+ content = { scopedSlots [ colName ] ( item , itemIndex + firstItemIndex ) }
460
463
/>
461
464
)
462
465
else
@@ -475,23 +478,21 @@ const CDataTable = props=>{
475
478
scopedSlots . details ?
476
479
< tr
477
480
className = "p-0"
478
- style = { { border :'none !important' } }
481
+ style = { { border : 'none !important' } }
479
482
key = { 'details' + itemIndex }
480
483
>
481
484
< td
482
485
colSpan = { colspan }
483
486
className = "p-0"
484
- style = { { border :'none !important' } }
487
+ style = { { border : 'none !important' } }
485
488
>
486
489
< Slot
487
- content = { detailsSlot }
488
- item = { item }
489
- index = { itemIndex + firstItemIndex }
490
+ content = { scopedSlots . details ( item , itemIndex + firstItemIndex ) }
490
491
/>
491
492
</ td >
492
493
</ tr > :''
493
494
}
494
- </ React . Fragment >
495
+ </ >
495
496
)
496
497
} ) }
497
498
{
@@ -584,15 +585,16 @@ const CDataTable = props=>{
584
585
585
586
{
586
587
//:activePage.sync="page"
588
+ //v-bind={typeof pagination === 'object' ? {...pagination} : null}
587
589
pagination ?
588
590
< CPagination
589
591
style = { { display : totalPages > 0 ? 'inline' : 'none' } }
590
592
pages = { totalPages }
591
- v-bind = { typeof pagination === 'object' ? { ...pagination } : null }
593
+ { ...paginationProps }
592
594
/> :''
593
595
}
594
596
595
- </ React . Fragment >
597
+ </ >
596
598
)
597
599
598
600
}
@@ -606,14 +608,15 @@ CDataTable.propTypes = {
606
608
//
607
609
innerRef : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func , PropTypes . string ] ) ,
608
610
overTableSlot : PropTypes . node ,
609
- colNameSlot : PropTypes . node ,
611
+ colNameSlot : PropTypes . node , //?
610
612
columnHeaderSlot : PropTypes . array ,
611
613
sortingIconSlot : PropTypes . node ,
612
614
columnFilterSlot : PropTypes . node ,
613
- detailsSlot : PropTypes . node ,
615
+ detailsSlot : PropTypes . node , //?
614
616
noItemViewSlot : PropTypes . node ,
615
617
captionSlot : PropTypes . node ,
616
618
underTableSlot : PropTypes . node ,
619
+ scopedSlots : PropTypes . object ,
617
620
fields : PropTypes . array ,
618
621
pagination : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . object ] ) ,
619
622
activePage : PropTypes . number ,
@@ -637,14 +640,19 @@ CDataTable.propTypes = {
637
640
itemsPerPageSelect : PropTypes . bool ,
638
641
loading : PropTypes . bool ,
639
642
change : PropTypes . func , //+
640
- onChange : PropTypes . func
643
+ onChange : PropTypes . func ,
644
+ sorterValue : PropTypes . object ,
645
+ columnFilterValue : PropTypes . object
641
646
}
642
647
643
648
CDataTable . defaultProps = {
644
649
itemsPerPage : 10 ,
645
650
responsive : true ,
646
651
columnHeaderSlot : [ ] ,
647
652
columnFilterSlot : [ ] ,
653
+ sorterValue : { }
648
654
}
649
655
656
+ CDataTable . Context = React . createContext ( { } ) ;
657
+
650
658
export default CDataTable ;
0 commit comments