@@ -14,10 +14,6 @@ import _tables from '../styles/_tables.scss';
1414export default class Table extends Component {
1515 constructor ( props ) {
1616 super ( props ) ;
17- this . state = {
18- sort : { }
19- } ;
20-
2117 this . onBodyScroll = this . onBodyScroll . bind ( this ) ;
2218 }
2319
@@ -54,7 +50,6 @@ export default class Table extends Component {
5450 if ( ! tr ) return ;
5551
5652 let ths = this . refs . header . querySelectorAll ( 'th' ) ;
57-
5853 let tds = tr . querySelectorAll ( 'td' ) ;
5954
6055 if ( tds . length <= 1 ) return ;
@@ -66,16 +61,6 @@ export default class Table extends Component {
6661 }
6762 }
6863
69- getSelected ( name ) {
70- let values = [ ] ;
71- this . state . data . forEach ( ( d ) => {
72- if ( d . $checked ) {
73- values . push ( name ? d [ name ] : d ) ;
74- }
75- } ) ;
76- return values ;
77- }
78-
7964 onBodyScroll ( e ) {
8065 let hc = this . refs . headerContainer ;
8166 hc . style . marginLeft = ( 0 - e . target . scrollLeft ) + 'px' ;
@@ -86,13 +71,14 @@ export default class Table extends Component {
8671 }
8772
8873 renderBody ( data ) {
89- const { selectAble, headers } = this . props ;
74+ const { selectAble } = this . props ;
75+ const columns = this . getColumns ( ) ;
9076
9177 if ( ! Array . isArray ( data ) ) {
92- return < tbody > < tr > < td colSpan = { headers . length } > { data } </ td > </ tr > </ tbody > ;
78+ return < tbody > < tr > < td colSpan = { columns . length } > { data } </ td > </ tr > </ tbody > ;
9379 }
9480
95- const headerKeys = headers . map ( ( h ) => {
81+ const headerKeys = columns . map ( ( h ) => {
9682 return h . name || hashcode ( h ) ;
9783 } ) ;
9884
@@ -106,7 +92,7 @@ export default class Table extends Component {
10692 ) ;
10793 }
10894 let rowKey = d . id ? d . id : hashcode ( d ) ;
109- headers . map ( ( h , j ) => {
95+ columns . map ( ( h , j ) => {
11096 if ( h . hidden ) {
11197 return ;
11298 }
@@ -127,17 +113,21 @@ export default class Table extends Component {
127113 }
128114
129115 renderColgroup ( ) {
130- const { selectAble, headers } = this . props ;
116+ const { selectAble } = this . props ;
131117 let cols = [ ] ;
132118 if ( selectAble ) {
133119 cols . push ( < col key = "check" /> ) ;
134120 }
135- headers . forEach ( ( h , i ) => {
121+ this . getColumns ( ) . forEach ( ( h , i ) => {
136122 cols . push ( < col key = { i } style = { h . width ? { width : h . width } : undefined } /> ) ;
137123 } ) ;
138124 return < colgroup > { cols } </ colgroup > ;
139125 }
140126
127+ getColumns ( ) {
128+ return this . props . columns || this . props . headers ( ) ;
129+ }
130+
141131 renderHeader ( ) {
142132 let headers = [ ] ;
143133 if ( this . props . selectAble ) {
@@ -147,19 +137,20 @@ export default class Table extends Component {
147137 } />
148138 ) ;
149139 }
150- this . props . headers . map ( ( header , i ) => {
140+
141+ const { onSort, sortStatus } = this . props ;
142+
143+ this . getColumns ( ) . forEach ( ( header , i ) => {
151144 if ( header . hidden ) {
152145 return ;
153146 }
154147
155- let props = {
156- key : header . name || i ,
157- onSort : this . props . onSort ,
158- sort : this . state . sort
159- } ;
160-
161148 headers . push (
162- < Header { ...header } { ...props } />
149+ < Header { ...header }
150+ key = { header . name || i }
151+ onSort = { onSort }
152+ sortStatus = { sortStatus }
153+ />
163154 ) ;
164155 } ) ;
165156 return < tr > { headers } </ tr > ;
@@ -170,7 +161,7 @@ export default class Table extends Component {
170161 if ( ! pagination ) return ;
171162
172163 return (
173- < div className = { _tables [ `pagi_ ${ pagination . position } ` ] } >
164+ < div className = { _tables [ `pagi- ${ pagination . position } ` ] } >
174165 < Pagination { ...pagination } />
175166 </ div >
176167 ) ;
@@ -236,13 +227,15 @@ Table.propTypes = {
236227 bordered : PropTypes . bool ,
237228 children : PropTypes . array ,
238229 className : PropTypes . string ,
230+ columns : PropTypes . array ,
239231 data : PropTypes . array ,
240232 filters : PropTypes . array ,
241233 headers : PropTypes . array ,
242234 height : PropTypes . number_string ,
243235 onSort : PropTypes . func ,
244236 pagination : PropTypes . object ,
245237 selectAble : PropTypes . bool ,
238+ sortStatus : PropTypes . object ,
246239 striped : PropTypes . bool ,
247240 style : PropTypes . object ,
248241 width : PropTypes . number_string
0 commit comments