From 18bb96c9694d5e760eec35d4242f56efe0a6828f Mon Sep 17 00:00:00 2001 From: Vi Pro Date: Thu, 28 Dec 2017 05:31:44 +0800 Subject: [PATCH] fix(MdTable): improve sort function on table for numbered columns (#1353) fix #1349 --- src/components/MdTable/MdTable.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/MdTable/MdTable.vue b/src/components/MdTable/MdTable.vue index b8d4f35f4..03731c5e9 100644 --- a/src/components/MdTable/MdTable.vue +++ b/src/components/MdTable/MdTable.vue @@ -105,12 +105,18 @@ const sortBy = this.MdTable.sort const aAttr = getObjectAttribute(a, sortBy) const bAttr = getObjectAttribute(b, sortBy) + const isAsc = this.MdTable.sortOrder === 'asc' + let isNumber = typeof aAttr === 'number' - if (this.MdTable.sortOrder === 'desc') { - return aAttr.localeCompare(bAttr) + if (isNumber) { + return isAsc ? (bAttr - aAttr) : (aAttr - bAttr) } - return bAttr.localeCompare(aAttr) + if (isAsc) { + return bAttr.localeCompare(aAttr) + } + + return aAttr.localeCompare(bAttr) }) } }