fix: added select row, select all row functionality in listview
This commit is contained in:
parent
3ccdc25645
commit
a8bdb2f550
@ -43,7 +43,11 @@
|
|||||||
id="list-header"
|
id="list-header"
|
||||||
class="flex space-x-4 items-center px-5 py-2 border-b"
|
class="flex space-x-4 items-center px-5 py-2 border-b"
|
||||||
>
|
>
|
||||||
<Checkbox class="[&>input]:duration-300 [&>input]:cursor-pointer" />
|
<Checkbox
|
||||||
|
class="[&>input]:duration-300 [&>input]:cursor-pointer"
|
||||||
|
:modelValue="allRowsSelected"
|
||||||
|
@click="toggleAllRows"
|
||||||
|
/>
|
||||||
<div
|
<div
|
||||||
v-for="column in columns"
|
v-for="column in columns"
|
||||||
:key="column"
|
:key="column"
|
||||||
@ -56,10 +60,19 @@
|
|||||||
<div id="list-rows" class="h-full overflow-y-auto">
|
<div id="list-rows" class="h-full overflow-y-auto">
|
||||||
<div
|
<div
|
||||||
v-for="row in rows"
|
v-for="row in rows"
|
||||||
:key="row"
|
:key="row[rowKey]"
|
||||||
class="flex space-x-4 items-center mx-2 px-3 py-2 border-b"
|
class="flex space-x-4 items-center mx-2 px-3 py-2 border-b cursor-pointer transition-all duration-200 ease-in-out"
|
||||||
|
:class="
|
||||||
|
selections.has(row[rowKey])
|
||||||
|
? 'bg-gray-100 hover:bg-gray-200'
|
||||||
|
: 'hover:bg-gray-50'
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<Checkbox class="[&>input]:duration-300 [&>input]:cursor-pointer" />
|
<Checkbox
|
||||||
|
:modelValue="selections.has(row[rowKey])"
|
||||||
|
@click="toggleRow(row[rowKey])"
|
||||||
|
class="[&>input]:duration-300 [&>input]:cursor-pointer"
|
||||||
|
/>
|
||||||
<div
|
<div
|
||||||
v-for="column in columns"
|
v-for="column in columns"
|
||||||
:key="column.key"
|
:key="column.key"
|
||||||
@ -102,7 +115,7 @@ import { FeatherIcon, Dropdown, Checkbox, Avatar } from 'frappe-ui'
|
|||||||
import SortIcon from './Icons/SortIcon.vue'
|
import SortIcon from './Icons/SortIcon.vue'
|
||||||
import FilterIcon from './Icons/FilterIcon.vue'
|
import FilterIcon from './Icons/FilterIcon.vue'
|
||||||
import IndicatorIcon from './Icons/IndicatorIcon.vue'
|
import IndicatorIcon from './Icons/IndicatorIcon.vue'
|
||||||
import { ref } from 'vue'
|
import { reactive, ref, computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
title: {
|
title: {
|
||||||
@ -117,6 +130,10 @@ const props = defineProps({
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: [],
|
default: [],
|
||||||
},
|
},
|
||||||
|
rowKey: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const currentView = ref({
|
const currentView = ref({
|
||||||
@ -174,8 +191,27 @@ function getValue(value) {
|
|||||||
value.image_label = value.image_label || value.label
|
value.image_label = value.image_label || value.label
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
return {
|
return { label: value }
|
||||||
label: value,
|
}
|
||||||
|
|
||||||
|
let selections = reactive(new Set())
|
||||||
|
|
||||||
|
const allRowsSelected = computed(() => {
|
||||||
|
if (!props.rows.length) return false
|
||||||
|
return selections.size === props.rows.length
|
||||||
|
})
|
||||||
|
|
||||||
|
function toggleRow(row) {
|
||||||
|
if (!selections.delete(row)) {
|
||||||
|
selections.add(row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleAllRows() {
|
||||||
|
if (allRowsSelected.value) {
|
||||||
|
selections.clear()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
props.rows.forEach((row) => selections.add(row[props.rowKey]))
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<ListView :title="title" :columns="columns" :rows="rows" />
|
<ListView :title="title" :columns="columns" :rows="rows" row-key="name" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@ -44,6 +44,7 @@ const columns = [
|
|||||||
const rows = computed(() => {
|
const rows = computed(() => {
|
||||||
return contacts.data?.map((contact) => {
|
return contacts.data?.map((contact) => {
|
||||||
return {
|
return {
|
||||||
|
name: contact.name,
|
||||||
full_name: {
|
full_name: {
|
||||||
label: contact.full_name,
|
label: contact.full_name,
|
||||||
image_label: contact.full_name,
|
image_label: contact.full_name,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<ListView :title="title" :columns="columns" :rows="rows" />
|
<ListView :title="title" :columns="columns" :rows="rows" row-key="name" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@ -76,6 +76,7 @@ const columns = [
|
|||||||
const rows = computed(() => {
|
const rows = computed(() => {
|
||||||
return leads.data?.map((lead) => {
|
return leads.data?.map((lead) => {
|
||||||
return {
|
return {
|
||||||
|
name: lead.name,
|
||||||
lead_name: {
|
lead_name: {
|
||||||
label: lead.lead_name,
|
label: lead.lead_name,
|
||||||
image: lead.image,
|
image: lead.image,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user