Skip to content
Permalink
Browse files

fix(MdTable): fix error to sort by attribute of child object (#1309)

* Fix error to sort by attribute of child object

* Fix attribute name

* Remove blank lines

* refactor(MdTable): cache attributes
  • Loading branch information...
gmenti authored and marcosmoura committed Dec 19, 2017
1 parent 49787d1 commit 9134227af2d71d95f0ea2a2e6a7890f5fcf5737d
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/components/MdTable/MdTable.vue
@@ -60,6 +60,16 @@
import MdTableRowGhost from './MdTableRowGhost'
import MdTableCellSelection from './MdTableCellSelection'
const getObjectAttribute = (object, key) => {
let value = object
for (const attribute of key.split('.')) {
value = value[attribute]
}
return value
}
export default {
name: 'MdTable',
components: {
@@ -93,12 +103,14 @@
default (value) {
return value.sort((a, b) => {
const sortBy = this.MdTable.sort
const aAttr = getObjectAttribute(a, sortBy)
const bAttr = getObjectAttribute(b, sortBy)
if (this.MdTable.sortOrder === 'desc') {
return a[sortBy].localeCompare(b[sortBy])
return aAttr.localeCompare(bAttr)
}
return b[sortBy].localeCompare(a[sortBy])
return bAttr.localeCompare(aAttr)
})
}
}

0 comments on commit 9134227

Please sign in to comment.
You can’t perform that action at this time.