-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fnSort prop in table and background in tags when change modelValue #521
Conversation
Emit event Sort for capture this event and filter data in backend
this could also work
Remove emit sort
Patch 1 to dev
Co-authored-by: Benjamin Canac <[email protected]>
Class priority issues in some cases when ring already defined on dark mode for example (input).
Co-authored-by: Benjamin Canac <[email protected]>
…modelValue changes don't touch playground/app.vue
Run & review this pull request in StackBlitz Codeflow. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
type: Object as PropType<{ column: string, direction: 'asc' | 'desc' }>, | ||
default: () => ({}) | ||
}, | ||
fnSort: { | ||
type: [ Function] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you think about adding fnSort
to main srot
prop like this
sort: {
type: Object as PropType<{ column: string, direction: 'asc' | 'desc', sortBy?: Function }>,
default: () => ({})
},
if (props.sort?.sortBy) {
sort.value.column = toSort.column
await props.sort.sortBy(toSort)
}
sort.value = toSort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better
<template>
<UTable
:sort="{
column: sortData.column,
direction: sortData.direction,
sortBy: fnSort
}"
:loading="loading"
:columns="columns"
:rows="data"
>
<template #url-data="{ row }">
<UAvatar :src="row.url" alt="Avatar" />
</template>
</UTable>
</template>
<script setup lang="ts">
const data = ref<[]>([])
const loading = ref<boolean>(false)
const sortData = ref<{ column: string | null; direction: 'asc' | 'desc'}>({
column: 'id',
direction: 'asc'
})
const columns = [{
key: 'id',
label: 'ID',
sortable: true
},
{
key: 'title',
label: 'Tile',
sortable: true
}, {
key: 'url',
label: 'IMG'
}]
async function fetchPhotos () {
try {
loading.value = true
const params = new URLSearchParams()
if (sortData.value.column && sortData.value.direction)
{
params.append('_sort', sortData.value.column)
params.append('_order', sortData.value.direction.toUpperCase())
}
const response = await fetch(`https://jsonplaceholder.typicode.com/photos?${params.toString()}`)
data.value = await response.json()
loading.value = false
}
catch (err) {
loading.value = false
console.log(err)
}
}
async function fnSort (sort: { column: string | null; direction: 'asc' | 'desc' }) {
sortData.value.column = sort.column
sortData.value.direction = sort.direction
await fetchPhotos()
}
onMounted(() => {
fetchPhotos()
})
</script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks more readable to avoid a lot of props in features
Closing in favor of #803 |
fnSort
is used when onSort is executed in the Table component, this function can give me the freedom to sort the data in my own way or ask the backend to change the order when there is a lot of datain template
in script
could be related to #390 #296
In tags when modelValue is changed, the background of selected is not assigned to the tag
this could be the solution