onSelect(row)" @contextmenu="(event) => onContextmenu(event, row)">
|
-
-
+ |
+
+ onSelect(row)"
+ />
+
+
+
{{ getRowData(row, column.key) }}
|
@@ -130,6 +137,7 @@ import type { PropType, AriaAttributes } from 'vue'
import { upperFirst } from 'scule'
import { defu } from 'defu'
import { useVModel } from '@vueuse/core'
+import { isEqual } from 'ohash'
import UIcon from '../elements/Icon.vue'
import UButton from '../elements/Button.vue'
import UProgress from '../elements/Progress.vue'
@@ -144,7 +152,7 @@ import { table } from '#ui/ui.config'
const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.table, table)
function defaultComparator(a: T, z: T): boolean {
- return JSON.stringify(a) === JSON.stringify(z)
+ return isEqual(a, z)
}
function defaultSort(a: any, b: any, direction: 'asc' | 'desc') {
@@ -159,6 +167,14 @@ function defaultSort(a: any, b: any, direction: 'asc' | 'desc') {
}
}
+function getStringifiedSet(arr: TableRow[]) {
+ return new Set(arr.map(item => JSON.stringify(item)))
+}
+
+function accessor>(key: string) {
+ return (obj: T) => get(obj, key)
+}
+
export default defineComponent({
components: {
UIcon,
@@ -247,6 +263,10 @@ export default defineComponent({
multipleExpand: {
type: Boolean,
default: true
+ },
+ singleSelect: {
+ type: Boolean,
+ default: false
}
},
emits: ['update:modelValue', 'update:sort', 'update:expand'],
@@ -292,8 +312,6 @@ export default defineComponent({
}
})
- const getStringifiedSet = (arr: TableRow[]) => new Set(arr.map(item => JSON.stringify(item)))
-
const totalRows = computed(() => props.rows.length)
const countCheckedRow = computed(() => {
@@ -328,10 +346,6 @@ export default defineComponent({
return props.by(a, z)
}
- function accessor>(key: string) {
- return (obj: T) => get(obj, key)
- }
-
function isSelected(row: TableRow) {
if (!props.modelValue) {
return false
@@ -397,7 +411,7 @@ export default defineComponent({
function onChangeCheckbox(checked: boolean, row: TableRow) {
if (checked) {
- selected.value.push(row)
+ selected.value = props.singleSelect ? [row] : [...selected.value, row]
} else {
const index = selected.value.findIndex(item => compare(item, row))
selected.value.splice(index, 1)
@@ -412,6 +426,13 @@ export default defineComponent({
return expand.value?.openedRows ? expand.value.openedRows.some(openedRow => compare(openedRow, row)) : false
}
+ function shouldRenderColumnInFirstPlace(index: number, key: string) {
+ if (!props.columns) {
+ return index === 0
+ }
+ return index === 0 && !props.columns.find(col => col.key === key)
+ }
+
function toggleOpened(row: TableRow) {
expand.value = {
openedRows: isExpanded(row) ? expand.value.openedRows.filter(v => !compare(v, row)) : props.multipleExpand ? [...expand.value.openedRows, row] : [row],
@@ -465,7 +486,8 @@ export default defineComponent({
getRowData,
toggleOpened,
getAriaSort,
- isExpanded
+ isExpanded,
+ shouldRenderColumnInFirstPlace
}
}
})
|