Skip to content

Commit

Permalink
fix(MdTable): fix error to sort by attribute of child object (#1309)
Browse files Browse the repository at this point in the history
* 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 9134227
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/MdTable/MdTable.vue
Expand Up @@ -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: {
Expand Down Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit 9134227

Please sign in to comment.