Skip to content

Commit 18bb96c

Browse files
VdustRmarcosmoura
authored andcommitted
fix(MdTable): improve sort function on table for numbered columns (#1353)
fix #1349
1 parent 567e9a7 commit 18bb96c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/MdTable/MdTable.vue

+9-3
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,18 @@
105105
const sortBy = this.MdTable.sort
106106
const aAttr = getObjectAttribute(a, sortBy)
107107
const bAttr = getObjectAttribute(b, sortBy)
108+
const isAsc = this.MdTable.sortOrder === 'asc'
109+
let isNumber = typeof aAttr === 'number'
108110
109-
if (this.MdTable.sortOrder === 'desc') {
110-
return aAttr.localeCompare(bAttr)
111+
if (isNumber) {
112+
return isAsc ? (bAttr - aAttr) : (aAttr - bAttr)
111113
}
112114
113-
return bAttr.localeCompare(aAttr)
115+
if (isAsc) {
116+
return bAttr.localeCompare(aAttr)
117+
}
118+
119+
return aAttr.localeCompare(bAttr)
114120
})
115121
}
116122
}

0 commit comments

Comments
 (0)