@@ -16,7 +16,7 @@ import Column from './Column'
16
16
import ColumnGroup from './ColumnGroup'
17
17
import createBodyRow from './createBodyRow'
18
18
import { flatArray , treeMap , flatFilter } from './util'
19
- import { initDefaultProps , mergeProps , getOptionProps } from '../_util/props-util'
19
+ import { initDefaultProps , mergeProps , getOptionProps , getComponentFromProp , isValidElement } from '../_util/props-util'
20
20
import BaseMixin from '../_util/BaseMixin'
21
21
import {
22
22
TableProps ,
@@ -437,7 +437,7 @@ export default {
437
437
let selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection )
438
438
const key = this . getRecordKey ( record , rowIndex )
439
439
const { pivot } = this . $data
440
- const rows = this . getFlatCurrentPageData ( )
440
+ const rows = this . getFlatCurrentPageData ( this . $props . childrenColumnName )
441
441
let realIndex = rowIndex
442
442
if ( this . $props . expandedRowRender ) {
443
443
realIndex = rows . findIndex ( row => this . getRecordKey ( row , rowIndex ) === key )
@@ -500,10 +500,8 @@ export default {
500
500
handleRadioSelect ( record , rowIndex , e ) {
501
501
const checked = e . target . checked
502
502
const nativeEvent = e . nativeEvent
503
- const defaultSelection = this . store . getState ( ) . selectionDirty ? [ ] : this . getDefaultSelection ( )
504
- let selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection )
505
503
const key = this . getRecordKey ( record , rowIndex )
506
- selectedRowKeys = [ key ]
504
+ const selectedRowKeys = [ key ]
507
505
this . store . setState ( {
508
506
selectionDirty : true ,
509
507
} )
@@ -517,7 +515,7 @@ export default {
517
515
} ,
518
516
519
517
handleSelectRow ( selectionKey , index , onSelectFunc ) {
520
- const data = this . getFlatCurrentPageData ( )
518
+ const data = this . getFlatCurrentPageData ( this . $props . childrenColumnName )
521
519
const defaultSelection = this . store . getState ( ) . selectionDirty ? [ ] : this . getDefaultSelection ( )
522
520
const selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection )
523
521
const changeableRowKeys = data
@@ -662,10 +660,10 @@ export default {
662
660
} ,
663
661
664
662
renderRowSelection ( locale ) {
665
- const { prefixCls, rowSelection } = this
663
+ const { prefixCls, rowSelection, childrenColumnName } = this
666
664
const columns = this . columns . concat ( )
667
665
if ( rowSelection ) {
668
- const data = this . getFlatCurrentPageData ( ) . filter ( ( item , index ) => {
666
+ const data = this . getFlatCurrentPageData ( childrenColumnName ) . filter ( ( item , index ) => {
669
667
if ( rowSelection . getCheckboxProps ) {
670
668
return ! this . getCheckboxPropsByItem ( item , index ) . props . disabled
671
669
}
@@ -741,6 +739,14 @@ export default {
741
739
const key = this . getColumnKey ( column , i )
742
740
let filterDropdown
743
741
let sortButton
742
+ let customHeaderCell = column . customHeaderCell
743
+ const { slots } = column
744
+ let title = column . title
745
+ if ( title === undefined && slots && slots . title ) {
746
+ title = this . $slots [ slots . title ]
747
+ title = title && title [ 0 ]
748
+ }
749
+ const sortTitle = this . getColumnTitle ( title , { } ) || locale . sortTitle
744
750
const isSortColumn = this . isSortColumn ( column )
745
751
if ( ( column . filters && column . filters . length > 0 ) || column . filterDropdown ) {
746
752
const colFilters = key in filters ? filters [ key ] : [ ]
@@ -759,12 +765,6 @@ export default {
759
765
)
760
766
}
761
767
if ( column . sorter ) {
762
- // const isSortColumn = this.isSortColumn(column)
763
- // if (isSortColumn) {
764
- // column.className = classNames(column.className, {
765
- // [`${prefixCls}-column-sort`]: sortOrder,
766
- // })
767
- // }
768
768
const isAscend = isSortColumn && sortOrder === 'ascend'
769
769
const isDescend = isSortColumn && sortOrder === 'descend'
770
770
sortButton = (
@@ -781,7 +781,27 @@ export default {
781
781
/>
782
782
</ div >
783
783
)
784
+ customHeaderCell = ( col ) => {
785
+ let colProps = { }
786
+ // Get original first
787
+ if ( column . customHeaderCell ) {
788
+ colProps = {
789
+ ...column . customHeaderCell ( col ) ,
790
+ }
791
+ }
792
+ colProps . on = colProps . on || { }
793
+ // Add sorter logic
794
+ const onHeaderCellClick = colProps . on . click
795
+ colProps . on . click = ( ...args ) => {
796
+ this . toggleSortOrder ( column )
797
+ if ( onHeaderCellClick ) {
798
+ onHeaderCellClick ( ...args )
799
+ }
800
+ }
801
+ return colProps
802
+ }
784
803
}
804
+ const sortTitleString = sortButton && typeof sortTitle === 'string' ? sortTitle : undefined
785
805
return {
786
806
...column ,
787
807
className : classNames ( column . className , {
@@ -793,29 +813,16 @@ export default {
793
813
title : [
794
814
< div
795
815
key = 'title'
796
- title = { sortButton ? locale . sortTitle : undefined }
816
+ title = { sortTitleString }
797
817
class = { sortButton ? `${ prefixCls } -column-sorters` : undefined }
798
- onClick = { ( ) => this . toggleSortOrder ( column ) }
799
818
>
800
819
{ this . renderColumnTitle ( column . title ) }
801
820
{ sortButton }
802
821
</ div > ,
803
822
filterDropdown ,
804
823
] ,
824
+ customHeaderCell,
805
825
}
806
- // column.title = (
807
- // <span key={key}>
808
- // {column.title}
809
- // {sortButton}
810
- // {filterDropdown}
811
- // </span>
812
- // )
813
-
814
- // if (sortButton || filterDropdown) {
815
- // column.className = classNames(`${prefixCls}-column-has-filters`, column.className)
816
- // }
817
-
818
- // return column
819
826
} )
820
827
} ,
821
828
renderColumnTitle ( title ) {
@@ -829,6 +836,23 @@ export default {
829
836
}
830
837
return title
831
838
} ,
839
+
840
+ getColumnTitle ( title , parentNode ) {
841
+ if ( ! title ) {
842
+ return
843
+ }
844
+ if ( isValidElement ( title ) ) {
845
+ debugger
846
+ const props = title . props
847
+ if ( props && props . children ) {
848
+ const { children } = props
849
+ return this . getColumnTitle ( children , props )
850
+ }
851
+ } else {
852
+ return parentNode . title || title
853
+ }
854
+ } ,
855
+
832
856
handleShowSizeChange ( current , pageSize ) {
833
857
const pagination = this . sPagination
834
858
pagination . onShowSizeChange ( current , pageSize )
@@ -939,11 +963,11 @@ export default {
939
963
} ,
940
964
941
965
getFlatData ( ) {
942
- return flatArray ( this . getLocalData ( ) )
966
+ return flatArray ( this . getLocalData ( null , false ) )
943
967
} ,
944
968
945
- getFlatCurrentPageData ( ) {
946
- return flatArray ( this . getCurrentPageData ( ) )
969
+ getFlatCurrentPageData ( childrenColumnName ) {
970
+ return flatArray ( this . getCurrentPageData ( ) , childrenColumnName )
947
971
} ,
948
972
949
973
recursiveSort ( data , sorterFn ) {
@@ -954,7 +978,7 @@ export default {
954
978
} : item ) )
955
979
} ,
956
980
957
- getLocalData ( state ) {
981
+ getLocalData ( state , filter = true ) {
958
982
const currentState = state || this . $data
959
983
const { sFilters : filters } = currentState
960
984
const { dataSource } = this . $props
@@ -966,7 +990,7 @@ export default {
966
990
data = this . recursiveSort ( data , sorterFn )
967
991
}
968
992
// 筛选
969
- if ( filters ) {
993
+ if ( filter && filters ) {
970
994
Object . keys ( filters ) . forEach ( ( columnKey ) => {
971
995
const col = this . findColumn ( columnKey )
972
996
if ( ! col ) {
0 commit comments