@@ -107,35 +107,79 @@ export const resetResize = (
107
107
}
108
108
} ;
109
109
110
- export const missingValuesFn = ( key : number , missingValues : { [ key : string | number ] : string } ) => {
111
- return key in missingValues ? missingValues [ key ] : key . toString ( ) ;
110
+ export const missingValuesFn = (
111
+ key : number | string ,
112
+ missingValues : { [ key : string | number ] : string }
113
+ ) => {
114
+ const foundKey =
115
+ typeof key === 'number' && key . toString ( ) . includes ( 'e' )
116
+ ? Object . keys ( missingValues ) . find ( ( item ) => {
117
+ return ( item as string ) . toLowerCase ( ) === key . toString ( ) . toLowerCase ( ) ;
118
+ } )
119
+ : typeof key === 'string' && parseInt ( key ) . toString ( ) . length !== key . length && new Date ( key )
120
+ ? Object . keys ( missingValues ) . find (
121
+ ( item ) => new Date ( item ) . getTime ( ) === new Date ( key ) . getTime ( )
122
+ )
123
+ : key in missingValues
124
+ ? key
125
+ : undefined ;
126
+
127
+ return foundKey ? missingValues [ foundKey ] : key ;
112
128
} ;
113
129
114
- export const convertServerColumns = ( columns : ServerColumn [ ] ) => {
130
+ export const convertServerColumns = (
131
+ serverColumns : ServerColumn [ ] ,
132
+ columns : Columns | undefined
133
+ ) => {
115
134
const columnsConfig : Columns = { } ;
116
135
117
- columns . forEach ( ( col ) => {
136
+ serverColumns . forEach ( ( col ) => {
118
137
let instructions = { } ;
119
138
120
139
if ( col . instructions ?. displayPattern ) {
140
+ let dp = col . instructions . displayPattern ;
141
+
142
+ // Swap 'm' and 'M' to match the backend date format
143
+ for ( let i = 0 ; i < col . instructions . displayPattern . length ; i ++ ) {
144
+ if ( col . instructions . displayPattern [ i ] === 'm' ) {
145
+ dp = `${ dp . slice ( 0 , i ) } M${ dp . slice ( i + 1 ) } ` ;
146
+ } else if ( col . instructions . displayPattern [ i ] === 'M' ) {
147
+ dp = `${ dp . slice ( 0 , i ) } m${ dp . slice ( i + 1 ) } ` ;
148
+ }
149
+ }
150
+
121
151
instructions = {
122
- toStringFn : ( date : Date ) => dateFormat ( date , col . instructions ?. displayPattern || '' ) ,
123
- toSortableValueFn : ( date : Date ) => date . getTime ( ) ,
124
- toFilterableValueFn : ( date : Date ) => date
152
+ toStringFn : ( date : string ) => {
153
+ if ( col . instructions ?. missingValues ) {
154
+ const missingValue = missingValuesFn ( date , col . instructions ?. missingValues || { } ) ;
155
+ if ( missingValue === date ) {
156
+ return dateFormat ( new Date ( date ) , dp ) ;
157
+ }
158
+ return missingValue ;
159
+ } else {
160
+ return dateFormat ( new Date ( date ) , dp ) ;
161
+ }
162
+ } ,
163
+ toSortableValueFn : ( date : string ) => new Date ( date ) . getTime ( ) ,
164
+ toFilterableValueFn : ( date : string ) => new Date ( date )
125
165
} ;
126
- }
127
-
128
- if ( col . instructions ?. missingValues ) {
166
+ } else if ( col . instructions ?. missingValues ) {
129
167
instructions = {
130
168
...instructions ,
131
169
toStringFn : ( key ) => missingValuesFn ( key , col . instructions ?. missingValues || { } )
132
170
} ;
133
171
}
134
172
135
- columnsConfig [ col . column ] = {
136
- exclude : col . exclude ,
137
- instructions
138
- } ;
173
+ if ( columns && col . column in columns ) {
174
+ columnsConfig [ col . column ] = {
175
+ ...columns [ col . column ] ,
176
+ instructions
177
+ } ;
178
+ } else {
179
+ columnsConfig [ col . column ] = {
180
+ instructions
181
+ } ;
182
+ }
139
183
} ) ;
140
184
141
185
return columnsConfig ;
0 commit comments