File tree 2 files changed +24
-5
lines changed
2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -241,10 +241,12 @@ export default {
241
241
sortable: true
242
242
},
243
243
city: {
244
- key: ' address.city'
244
+ key: ' address.city' ,
245
+ sortable: true
245
246
},
246
247
' address.country' : {
247
- label: ' Country'
248
+ label: ' Country' ,
249
+ sortable: true
248
250
}
249
251
},
250
252
items: [
Original file line number Diff line number Diff line change @@ -40,14 +40,31 @@ function recToString (obj) {
40
40
}
41
41
42
42
function defaultSortCompare ( a , b , sortBy ) {
43
- if ( typeof a [ sortBy ] === 'number' && typeof b [ sortBy ] === 'number' ) {
44
- return ( a [ sortBy ] < b [ sortBy ] && - 1 ) || ( a [ sortBy ] > b [ sortBy ] && 1 ) || 0
43
+ if ( sortBy . indexOf ( '.' ) < 0 ) {
44
+ return sort ( a [ sortBy ] , b [ sortBy ] )
45
+ } else {
46
+ return sort ( getNestedValue ( a , sortBy ) , getNestedValue ( b , sortBy ) )
45
47
}
46
- return toString ( a [ sortBy ] ) . localeCompare ( toString ( b [ sortBy ] ) , undefined , {
48
+ }
49
+
50
+ function sort ( a , b ) {
51
+ if ( typeof a === 'number' && typeof b === 'number' ) {
52
+ return ( a < b && - 1 ) || ( a > b && 1 ) || 0
53
+ }
54
+ return toString ( a ) . localeCompare ( toString ( b ) , undefined , {
47
55
numeric : true
48
56
} )
49
57
}
50
58
59
+ function getNestedValue ( obj , path ) {
60
+ path = path . split ( '.' )
61
+ var value = obj
62
+ for ( var i = 0 ; i < path . length ; i ++ ) {
63
+ value = value [ path [ i ] ]
64
+ }
65
+ return value
66
+ }
67
+
51
68
function processField ( key , value ) {
52
69
let field = null
53
70
if ( typeof value === 'string' ) {
You can’t perform that action at this time.
0 commit comments