Skip to content

Commit

Permalink
fix(Table): respect sort prop updates from parent component (#1208)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
  • Loading branch information
ivantopo and benjamincanac authored Jan 9, 2024
1 parent 8508e84 commit c6841d0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/runtime/components/data/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@
</template>
<script lang="ts">
import { ref, computed, defineComponent, toRaw, toRef } from 'vue'
import { computed, defineComponent, toRaw, toRef } from 'vue'
import type { PropType } from 'vue'
import { upperFirst } from 'scule'
import { defu } from 'defu'
import { useVModel } from '@vueuse/core'
import UButton from '../elements/Button.vue'
import UIcon from '../elements/Icon.vue'
import UCheckbox from '../forms/Checkbox.vue'
Expand Down Expand Up @@ -170,7 +171,7 @@ export default defineComponent({
const columns = computed(() => props.columns ?? Object.keys(props.rows[0] ?? {}).map((key) => ({ key, label: upperFirst(key), sortable: false, class: undefined, sort: defaultSort })))
const sort = ref(defu({}, props.sort, { column: null, direction: 'asc' }))
const sort = useVModel(props, 'sort', emit, { passive: true, defaultValue: defu({}, props.sort, { column: null, direction: 'asc' }) })
const savedSort = { column: sort.value.column, direction: null }
Expand Down Expand Up @@ -235,13 +236,11 @@ export default defineComponent({
if (sort.value.direction === direction) {
sort.value = defu({}, savedSort, { column: null, direction: 'asc' })
} else {
sort.value.direction = sort.value.direction === 'asc' ? 'desc' : 'asc'
sort.value = { column: sort.value.column, direction: sort.value.direction === 'asc' ? 'desc' : 'asc' }
}
} else {
sort.value = { column: column.key, direction: column.direction || 'asc' }
}
emit('update:sort', sort.value)
}
function onSelect (row) {
Expand Down

1 comment on commit c6841d0

@vercel
Copy link

@vercel vercel bot commented on c6841d0 Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxt-js.vercel.app
ui.nuxt.com
ui-git-dev-nuxt-js.vercel.app

Please sign in to comment.