1
1
import React from 'react' ;
2
- import { View , ScrollView } from 'react-native' ;
2
+ import { View , ScrollView } from 'react-native' ;
3
3
import DataTableRow from './DataTableRow' ;
4
4
import DataTableFooter from './DataTableFooter' ;
5
5
import DataTableHeader from './DataTableHeader' ;
6
- import Line from './Line' ;
7
6
import sortData from '../functions/sort' ;
8
7
import showCurrentProgress from '../functions/showCurrentProgress' ;
9
8
@@ -23,6 +22,7 @@ interface PropTypes {
23
22
onRowSelect ?: ( anyVariable ) => object ;
24
23
backgroundColor ?: string ;
25
24
doSort ?: boolean ;
25
+ stickyHeader ?: boolean ;
26
26
headerLabelStyle ?: object ;
27
27
}
28
28
@@ -40,7 +40,7 @@ class DataTable extends React.Component<PropTypes> {
40
40
endDataArray : [ ] , //[{id, endData}]
41
41
noOfPages : 3 , //default
42
42
activeDisplayDataId : 0 ,
43
- mapColNameToType : { }
43
+ mapColNameToType : { } ,
44
44
}
45
45
46
46
@@ -122,7 +122,7 @@ class DataTable extends React.Component<PropTypes> {
122
122
data : props . data ,
123
123
colSettings : props . colSettings ,
124
124
colNames : props . colNames ,
125
- noOfPages : props . noOfPages
125
+ noOfPages : props . noOfPages ,
126
126
} )
127
127
128
128
if ( snap == currentState . snap ) return null ;
@@ -180,41 +180,49 @@ class DataTable extends React.Component<PropTypes> {
180
180
} ;
181
181
}
182
182
183
- render ( ) {
184
-
183
+ renderItem = ( item , index ) => {
185
184
return (
186
- < View style = { { backgroundColor : this . props . backgroundColor ? this . props . backgroundColor : '#e4edec' } }
187
- onLayout = { e => {
188
- this . setState ( { widthOfContainer : e . nativeEvent . layout . width } )
189
- } } >
190
-
191
- < DataTableHeader
192
- colNames = { this . state . colNames }
193
- mapColNameToType = { this . state . mapColNameToType }
194
- defaultEachColumnWidth = { this . state . defaultEachColumnWidth }
195
- eachColWidth = { this . state . eachColWidth }
196
- handleColPress = { this . handleColPress }
197
- doSort = { this . props ?. doSort }
198
- style = { this . props ?. headerLabelStyle }
199
- />
185
+ < DataTableRow
186
+ handleOnRowSelect = { this . handleOnRowSelect }
187
+ key = { index }
188
+ index = { index }
189
+ data = { item }
190
+ mapColNameToType = { this . state . mapColNameToType }
191
+ colNames = { this . state . colNames }
192
+ eachColWidth = { this . state . eachColWidth }
193
+ defaultEachColumnWidth = { this . state . defaultEachColumnWidth }
194
+ />
195
+ ) ;
196
+ }
200
197
201
- < Line width = { this . state . widthOfContainer } header />
202
- < ScrollView >
203
- {
204
- this . state . displayData . map ( ( item , index ) => (
205
- < DataTableRow
206
- handleOnRowSelect = { this . handleOnRowSelect }
207
- widthOfLine = { this . state . widthOfContainer }
208
- key = { index }
209
- index = { index }
210
- data = { item }
211
- mapColNameToType = { this . state . mapColNameToType }
212
- colNames = { this . state . colNames }
213
- eachColWidth = { this . state . eachColWidth }
214
- defaultEachColumnWidth = { this . state . defaultEachColumnWidth }
215
- />
216
- ) )
217
- }
198
+ render ( ) {
199
+ return (
200
+ < View
201
+ onLayout = { e => this . setState ( { widthOfContainer : e . nativeEvent . layout . width } ) }
202
+ style = { { flex : 1 , backgroundColor : this . props . backgroundColor ? this . props . backgroundColor : '#e4edec' } } >
203
+ < ScrollView
204
+ nestedScrollEnabled = { true }
205
+ bounces = { false }
206
+ horizontal = { true }
207
+ showsHorizontalScrollIndicator = { false } >
208
+ < ScrollView
209
+ bounces = { false }
210
+ showsVerticalScrollIndicator = { false }
211
+ stickyHeaderIndices = { this . props ?. stickyHeader === false ? [ ] : [ 0 ] } >
212
+ < DataTableHeader
213
+ colNames = { this . state . colNames }
214
+ mapColNameToType = { this . state . mapColNameToType }
215
+ defaultEachColumnWidth = { this . state . defaultEachColumnWidth }
216
+ eachColWidth = { this . state . eachColWidth }
217
+ handleColPress = { this . handleColPress }
218
+ doSort = { this . props ?. doSort }
219
+ style = { this . props ?. headerLabelStyle }
220
+ backgroundColor = { this . props . backgroundColor ? this . props . backgroundColor : '#e4edec' }
221
+ />
222
+ { this . state . displayData . map ( ( item , index ) => {
223
+ return this . renderItem ( item , index ) ;
224
+ } ) }
225
+ </ ScrollView >
218
226
</ ScrollView >
219
227
< DataTableFooter
220
228
start = { this . state . startDataArray }
@@ -223,7 +231,6 @@ class DataTable extends React.Component<PropTypes> {
223
231
dataLength = { this . state . data . length }
224
232
handleNextPreviousPagePress = { this . handleNextPreviousPagePress }
225
233
/>
226
-
227
234
</ View >
228
235
) ;
229
236
}
0 commit comments