@@ -16,7 +16,7 @@ import Column from './Column'
1616import ColumnGroup from './ColumnGroup'
1717import createBodyRow from './createBodyRow'
1818import { 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'
2020import BaseMixin from '../_util/BaseMixin'
2121import {
2222 TableProps ,
@@ -437,7 +437,7 @@ export default {
437437 let selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection )
438438 const key = this . getRecordKey ( record , rowIndex )
439439 const { pivot } = this . $data
440- const rows = this . getFlatCurrentPageData ( )
440+ const rows = this . getFlatCurrentPageData ( this . $props . childrenColumnName )
441441 let realIndex = rowIndex
442442 if ( this . $props . expandedRowRender ) {
443443 realIndex = rows . findIndex ( row => this . getRecordKey ( row , rowIndex ) === key )
@@ -500,10 +500,8 @@ export default {
500500 handleRadioSelect ( record , rowIndex , e ) {
501501 const checked = e . target . checked
502502 const nativeEvent = e . nativeEvent
503- const defaultSelection = this . store . getState ( ) . selectionDirty ? [ ] : this . getDefaultSelection ( )
504- let selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection )
505503 const key = this . getRecordKey ( record , rowIndex )
506- selectedRowKeys = [ key ]
504+ const selectedRowKeys = [ key ]
507505 this . store . setState ( {
508506 selectionDirty : true ,
509507 } )
@@ -517,7 +515,7 @@ export default {
517515 } ,
518516
519517 handleSelectRow ( selectionKey , index , onSelectFunc ) {
520- const data = this . getFlatCurrentPageData ( )
518+ const data = this . getFlatCurrentPageData ( this . $props . childrenColumnName )
521519 const defaultSelection = this . store . getState ( ) . selectionDirty ? [ ] : this . getDefaultSelection ( )
522520 const selectedRowKeys = this . store . getState ( ) . selectedRowKeys . concat ( defaultSelection )
523521 const changeableRowKeys = data
@@ -662,10 +660,10 @@ export default {
662660 } ,
663661
664662 renderRowSelection ( locale ) {
665- const { prefixCls, rowSelection } = this
663+ const { prefixCls, rowSelection, childrenColumnName } = this
666664 const columns = this . columns . concat ( )
667665 if ( rowSelection ) {
668- const data = this . getFlatCurrentPageData ( ) . filter ( ( item , index ) => {
666+ const data = this . getFlatCurrentPageData ( childrenColumnName ) . filter ( ( item , index ) => {
669667 if ( rowSelection . getCheckboxProps ) {
670668 return ! this . getCheckboxPropsByItem ( item , index ) . props . disabled
671669 }
@@ -741,6 +739,14 @@ export default {
741739 const key = this . getColumnKey ( column , i )
742740 let filterDropdown
743741 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
744750 const isSortColumn = this . isSortColumn ( column )
745751 if ( ( column . filters && column . filters . length > 0 ) || column . filterDropdown ) {
746752 const colFilters = key in filters ? filters [ key ] : [ ]
@@ -759,12 +765,6 @@ export default {
759765 )
760766 }
761767 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- // }
768768 const isAscend = isSortColumn && sortOrder === 'ascend'
769769 const isDescend = isSortColumn && sortOrder === 'descend'
770770 sortButton = (
@@ -781,7 +781,27 @@ export default {
781781 />
782782 </ div >
783783 )
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+ }
784803 }
804+ const sortTitleString = sortButton && typeof sortTitle === 'string' ? sortTitle : undefined
785805 return {
786806 ...column ,
787807 className : classNames ( column . className , {
@@ -793,29 +813,16 @@ export default {
793813 title : [
794814 < div
795815 key = 'title'
796- title = { sortButton ? locale . sortTitle : undefined }
816+ title = { sortTitleString }
797817 class = { sortButton ? `${ prefixCls } -column-sorters` : undefined }
798- onClick = { ( ) => this . toggleSortOrder ( column ) }
799818 >
800819 { this . renderColumnTitle ( column . title ) }
801820 { sortButton }
802821 </ div > ,
803822 filterDropdown ,
804823 ] ,
824+ customHeaderCell,
805825 }
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
819826 } )
820827 } ,
821828 renderColumnTitle ( title ) {
@@ -829,6 +836,23 @@ export default {
829836 }
830837 return title
831838 } ,
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+
832856 handleShowSizeChange ( current , pageSize ) {
833857 const pagination = this . sPagination
834858 pagination . onShowSizeChange ( current , pageSize )
@@ -939,11 +963,11 @@ export default {
939963 } ,
940964
941965 getFlatData ( ) {
942- return flatArray ( this . getLocalData ( ) )
966+ return flatArray ( this . getLocalData ( null , false ) )
943967 } ,
944968
945- getFlatCurrentPageData ( ) {
946- return flatArray ( this . getCurrentPageData ( ) )
969+ getFlatCurrentPageData ( childrenColumnName ) {
970+ return flatArray ( this . getCurrentPageData ( ) , childrenColumnName )
947971 } ,
948972
949973 recursiveSort ( data , sorterFn ) {
@@ -954,7 +978,7 @@ export default {
954978 } : item ) )
955979 } ,
956980
957- getLocalData ( state ) {
981+ getLocalData ( state , filter = true ) {
958982 const currentState = state || this . $data
959983 const { sFilters : filters } = currentState
960984 const { dataSource } = this . $props
@@ -966,7 +990,7 @@ export default {
966990 data = this . recursiveSort ( data , sorterFn )
967991 }
968992 // 筛选
969- if ( filters ) {
993+ if ( filter && filters ) {
970994 Object . keys ( filters ) . forEach ( ( columnKey ) => {
971995 const col = this . findColumn ( columnKey )
972996 if ( ! col ) {
0 commit comments