@@ -19,12 +19,20 @@ const withContext = (Base) => {
19
19
constructor ( props ) {
20
20
super ( props ) ;
21
21
DataContext = createDataContext ( props . data ) ;
22
- SelectionContext = createSelectionContext ( dataOperator ) ;
23
- SortContext = createSortContext ( dataOperator , this . isRemoteSort , this . handleSortChange ) ;
22
+
23
+ if ( props . columns . filter ( col => col . sort ) . length > 0 ) {
24
+ SortContext = createSortContext ( dataOperator , this . isRemoteSort , this . handleSortChange ) ;
25
+ }
26
+
27
+ if ( props . selectRow ) {
28
+ SelectionContext = createSelectionContext ( dataOperator ) ;
29
+ }
30
+
24
31
if ( props . cellEdit && props . cellEdit . createContext ) {
25
32
CellEditContext = props . cellEdit . createContext (
26
33
_ , dataOperator , this . isRemoteCellEdit , this . handleCellChange ) ;
27
34
}
35
+
28
36
if ( props . filter ) {
29
37
FilterContext = props . filter . createContext (
30
38
_ , this . isRemoteFiltering , this . handleRemoteFilterChange ) ;
@@ -37,7 +45,7 @@ const withContext = (Base) => {
37
45
}
38
46
}
39
47
40
- renderBase ( baseProps ) {
48
+ renderBaseTemp ( baseProps ) {
41
49
return ( rootProps , cellEditProps , filterProps ) => (
42
50
< SortContext . Provider
43
51
{ ...baseProps }
@@ -76,28 +84,108 @@ const withContext = (Base) => {
76
84
) ;
77
85
}
78
86
79
- renderWithFilter ( base , baseProps ) {
80
- return ( rootProps , cellEditprops ) => (
87
+ renderBase ( ) {
88
+ return (
89
+ rootProps ,
90
+ cellEditProps ,
91
+ filterProps ,
92
+ sortProps ,
93
+ selectionProps
94
+ ) => (
95
+ < Base
96
+ { ...this . props }
97
+ { ...selectionProps }
98
+ { ...sortProps }
99
+ { ...cellEditProps }
100
+ { ...filterProps }
101
+ data = { rootProps . getData ( filterProps , sortProps ) }
102
+ />
103
+ ) ;
104
+ }
105
+
106
+ renderWithSelectionCtx ( base , baseProps ) {
107
+ return (
108
+ rootProps ,
109
+ cellEditProps ,
110
+ filterProps ,
111
+ sortProps
112
+ ) => (
113
+ < SelectionContext . Provider
114
+ { ...baseProps }
115
+ selectRow = { this . props . selectRow }
116
+ data = { rootProps . getData ( filterProps , sortProps ) }
117
+ >
118
+ < SelectionContext . Consumer >
119
+ {
120
+ selectionProps => base (
121
+ rootProps ,
122
+ cellEditProps ,
123
+ filterProps ,
124
+ sortProps ,
125
+ selectionProps
126
+ )
127
+ }
128
+ </ SelectionContext . Consumer >
129
+ </ SelectionContext . Provider >
130
+ ) ;
131
+ }
132
+
133
+ renderWithSortCtx ( base , baseProps ) {
134
+ return (
135
+ rootProps ,
136
+ cellEditProps ,
137
+ filterProps
138
+ ) => (
139
+ < SortContext . Provider
140
+ { ...baseProps }
141
+ ref = { n => this . sortContext = n }
142
+ defaultSorted = { this . props . defaultSorted }
143
+ defaultSortDirection = { this . props . defaultSortDirection }
144
+ data = { rootProps . getData ( filterProps ) }
145
+ >
146
+ < SortContext . Consumer >
147
+ {
148
+ sortProps => base (
149
+ rootProps ,
150
+ cellEditProps ,
151
+ filterProps ,
152
+ sortProps
153
+ )
154
+ }
155
+ </ SortContext . Consumer >
156
+ </ SortContext . Provider >
157
+ ) ;
158
+ }
159
+
160
+ renderWithFilterCtx ( base , baseProps ) {
161
+ return (
162
+ rootProps ,
163
+ cellEditprops
164
+ ) => (
81
165
< FilterContext . Provider
82
166
{ ...baseProps }
83
167
ref = { n => this . filterContext = n }
84
- data = { rootProps . data }
168
+ data = { rootProps . getData ( ) }
85
169
>
86
170
< FilterContext . Consumer >
87
171
{
88
- filterProps => base ( rootProps , cellEditprops , filterProps )
172
+ filterProps => base (
173
+ rootProps ,
174
+ cellEditprops ,
175
+ filterProps
176
+ )
89
177
}
90
178
</ FilterContext . Consumer >
91
179
</ FilterContext . Provider >
92
180
) ;
93
181
}
94
182
95
- renderWithCellEdit ( base , baseProps ) {
183
+ renderWithCellEditCtx ( base , baseProps ) {
96
184
return rootProps => (
97
185
< CellEditContext . Provider
98
186
{ ...baseProps }
99
187
cellEdit = { this . props . cellEdit }
100
- data = { rootProps . data }
188
+ data = { rootProps . getData ( ) }
101
189
>
102
190
< CellEditContext . Consumer >
103
191
{
@@ -112,14 +200,22 @@ const withContext = (Base) => {
112
200
const { keyField, columns } = this . props ;
113
201
const baseProps = { keyField, columns } ;
114
202
115
- let base = this . renderBase ( baseProps ) ;
203
+ let base = this . renderBase ( ) ;
204
+
205
+ if ( SelectionContext ) {
206
+ base = this . renderWithSelectionCtx ( base , baseProps ) ;
207
+ }
208
+
209
+ if ( SortContext ) {
210
+ base = this . renderWithSortCtx ( base , baseProps ) ;
211
+ }
116
212
117
213
if ( FilterContext ) {
118
- base = this . renderWithFilter ( base , baseProps ) ;
214
+ base = this . renderWithFilterCtx ( base , baseProps ) ;
119
215
}
120
216
121
217
if ( CellEditContext ) {
122
- base = this . renderWithCellEdit ( base , baseProps ) ;
218
+ base = this . renderWithCellEditCtx ( base , baseProps ) ;
123
219
}
124
220
125
221
return (
0 commit comments