File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -248,14 +248,31 @@ export class SortExecutor extends TransformExecutor {
248248 public apply ( input : TransformExecutor . IData ) : TransformExecutor . IData {
249249 let sortFunc : ( a : any , b : any ) => number ;
250250 const field = this . _options . field ;
251+ const columnDataType = this . _options . dType ;
252+
253+ // Adding string checks within the sort function so we do
254+ // not have to mutate in-place the original types of the
255+ // values of the column into strings. This allows the
256+ // displayed values to maintain their original types but
257+ // be sorted as if they were all strings.
258+ const stringifyIfNeeded = ( value : any ) => {
259+ if ( typeof value != 'string' && columnDataType == 'string' ) {
260+ return String ( value ) ;
261+ }
262+ return value ;
263+ } ;
251264
252265 if ( this . _options . desc ) {
253266 sortFunc = ( a : any , b : any ) : number => {
254- return a [ field ] < b [ field ] ? 1 : - 1 ;
267+ return stringifyIfNeeded ( a [ field ] ) < stringifyIfNeeded ( b [ field ] )
268+ ? 1
269+ : - 1 ;
255270 } ;
256271 } else {
257272 sortFunc = ( a : any , b : any ) : number => {
258- return a [ field ] > b [ field ] ? 1 : - 1 ;
273+ return stringifyIfNeeded ( a [ field ] ) > stringifyIfNeeded ( b [ field ] )
274+ ? 1
275+ : - 1 ;
259276 } ;
260277 }
261278
You can’t perform that action at this time.
0 commit comments