v-select deactivate some items/options - filter

I am using vuetify's to display dropdowns.
The options come from my components data.
What I would like to do now is to deactivate only some of the items in the v-select. What items are deactivated and which are activated will later on depend on the user input.
I can only find the option to deactivate the whole v-select like by adding disabled="true" to the v-select.
My code looks like this right now:
<v-row
v-for="(part, index) in xy"
:key="index">
<v-col md="3" sm="3">
<v-card ripple >
<v-img
src="src/assets/test.PNG"
></v-img>
</v-card>
</v-col>
<v-col md="8" sm="3">
<v-select
v- model="dropdownValues[index]"
:items="part"
hide-details
label="Select value"
single-line
#change="changeInput(index, dropdownValues[index])"
#click:append-outer="resetInput(index)"
>
<template slot="append-outer">
<v-icon #click="resetInput(index)">
mdi-close
</v-icon>
</template>
<template
slot="{item, index}">
{{ index }}
</template>
</v-select>
</v-col>
</v-row>
I thought that I could do the items via this slot possibility but now I am unsure where and how to add the functionality of changing which items are deactive and which not.
Thanks in advance!

<v-select> items array with objects can have an additional property disabled that currently is not documented.
data: () => ({
items: [
{ text: 'Empty', value: '' },
{ text: 'Test1', value: 'test1', disabled: true },
{ text: 'Test2', value: 'test2' },
{ text: 'Test3', value: 'test3' },
{ text: 'Test4', value: 'test4' },
]
}),
You can return the filtered array of objects as computed property you can see some demo example in here:
https://codepen.io/edenkindil/pen/RwrZMXy
BTW you can change this property key like to the text and value with the item-disabled just like you would use the item-text or item-value
Update: Vuetify docs is now updated
You can see now all the available items in array of objects:
{
text: string | number | object
value: string | number | object
disabled: boolean
divider: boolean
header: string
}

Related

vuetify v-data-table rows with different methods in items

i have a two-way binding object with a group of inputs
<v-text-field
label="Workers"
v-model="myObject.workers">
</v-text-field>
myObject: any = {
workers: 2,
hours: 16,
nights: 2,
}
which will be used for my data-table items
private myHeaders: any = [
{
text: 'Pos.',
value: 'pos',
},
{
text: 'Description',
value: 'descr',
},
{
text: 'Workers',
value: 'workers',
},
{
text: 'Hours',
value: 'hours',
}
]
private myItems: any = [
{
descr: 'someName',
workers: this.montageService.method_1(this.myObject),
hours: this.montageService.method_2(this.myObject),
},
{
descr: 'anotherName',
workers: this.montageService.method_3(this.myObject),
hours: this.montageService.method_4(this.myObject),
}]
The Object this.myObject is updating but the table is not. the methods will not be triggered in myItems.
here is the data-table:
<v-data-table
:headers="myHeaders"
:items="myItems"
>
<template v-slot:item.pos="{item, index}">
{{ index }}
</template>
<template v-slot:item.descr="{item}">
{{ item.descr }}
</template>
<template v-slot:item.workers="{item}">
{{ item.workers }}
</template>
<template v-slot:item.hours="{item}">
{{ item.hours | toCurrency}}
</template>
</v-data-table>
I used a v-simple-table before, but to make the rows/values editable i think i needed to change to v-data-table. When i implement the functions in the data-table, its working with updated two-way binding object. But since there are different methods for each row to be used, i moved the functions to myItems

Vuetify groupable table, is there a way to edit the the group name format?

The Vuetify table has an group-by prop, but instead of showing the header text it shows header value and then the group. Is there possible to change that?
What I'm looking for is like in the screenshot below, you can see the groups are like 'category: Candy'. The 'category' here is the header value. Is there a way to change it to 'Category' which would be the text?
{ text: 'Category', value: 'category', align: 'right' },
I could not find an appropriate attribute for you to set, but what could be used is a predefined object in the group.header slot:
<v-data-table :headers="headers" :items="desserts" item-key="name" sort-by="name" group-by="category" class="elevation-1" show-group-by>
<template v-slot:group.header="{groupBy, group, isOpen, toggle, remove}">
<td :colspan="headers.length">
<v-icon #click="toggle">
{{ isOpen ? 'mdi-minus' : 'mdi-plus' }}
</v-icon>
<span>{{customGroupNames[groupBy[0]]}} : {{group}}</span>
<v-icon #click="remove">
mdi-close
</v-icon>
</td>
</template>
</v-data-table>
Then you have to set the customGroupNames variable in your component:
data() {
return {
customGroupNames: { "category": "Cat", "dairy": "Dairy" },
headers: [...],
dessserts: [...]
}
}
You would essentially have to rebuild the group header row, but you will be able to display whatever you like.

Vuetify breadcrumbs text color

I'm trying to have different text colors for my breadcrumbs based on a property but I can't figure out how to apply those colors anywhere. Can't add a color or class in the items either.
breadcrumbItems() {
return [
{
text: this.$t("receiving.breadcrumbs.step1"),
disabled: this.item.Status !== "STEP1"
},
{
text: this.$t("receiving.breadcrumbs.step2"),
disabled: this.item.Status !== "STEP2"
},
{
text: this.$t("receiving.breadcrumbs.step3"),
disabled: this.item.Status !== "STEP3"
}
];
}
<v-breadcrumbs :items="breadcrumbItems" class="breadStyle">
<template v-slot:divider>
<v-icon size="25">mdi-forward</v-icon>
</template>
</v-breadcrumbs>
Looking at the API for v-breadcrumbs: https://vuetifyjs.com/en/api/v-breadcrumbs-item/ it doesn't provide a property "color" or something similar, but there is a slot, so you can pass any kind of components in it.
You can create a <span> and customize its color and its style depending on the items:
<template>
<v-breadcrumbs :items="items">
<template v-slot:divider>
<v-icon size="25">mdi-forward</v-icon>
</template>
<template v-slot:item="{ item }">
<v-breadcrumbs-item :disabled="item.disabled">
<span :style="`color: ${item.color}`">
{{ item.text.toUpperCase() }}
</span>
</v-breadcrumbs-item>
</template>
</v-breadcrumbs>
</template>
<script>
export default {
data: () => ({
items: [
{
text: "Dashboard",
disabled: false,
color: "green",
},
{
text: "Link 1",
disabled: false,
color: "blue",
},
{
text: "Link 2",
disabled: true,
color: "red",
},
],
}),
};
</script>
I've found that the deep selector (https://vue-loader.vuejs.org/guide/scoped-css.html#deep-selectors) often helps with styling Vuetify components. I added this to my components scoped CSS and the colours work just fine for links:
.v-breadcrumbs >>> a {
color: purple;
}
I found the relevant tag by looking through the Elements-tab under Inspect (in Chrome).
I don't know if this is the best solution for your specific situation, but figured I'd add this for anyone with a simpler use case.

Use Chips in Vue Text Field

How can I use chips in a Vue Text Field? The functionality I'm trying to replicate is kinda similar to the StackOverflow's Tag field. However I do not want auto-complete nor a dropdown list. Just a simple text field that displays chips for the items.
I have this
however im trying to get this
component.vue
<v-combobox
v-model="item.tokens"
chips
clearable
multiple
filled
rounded
>
<template v-slot:selection="{ attrs, item, select, selected }">
<v-chip
small
v-bind="attrs"
:input-value="selected"
close
#click="select"
#click:close="remove(item)"
>
{{ item }}
</v-chip>
</template>
</v-combobox>
<script>
export default {
data() {
return {
items: [
{
name: "Apples",
tokens: [
"_apple",
"_a",
],
backgroundColor: "#000000",
backgroundEnabled: false
},
{
name: "Oranges",
tokens: ["_orange", "_o"],
backgroundColor: "#000000",
backgroundEnabled: false
},
{
name: "Grapes",
tokens: ["_grape", "_g", "_grapes"],
backgroundColor: "#000000",
backgroundEnabled: false
}
]
};
},
};
</script>
Add the props append-icon="" in your v-combobox.
You will have something like this :
<v-combobox
v-model="item.tokens"
chips
clearable
multiple
filled
rounded
append-icon=""
>
<template v-slot:selection="{ attrs, item, select, selected }">
<v-chip
small
v-bind="attrs"
:input-value="selected"
close
#click="select"
#click:close="remove(item)"
>
{{ item }}
</v-chip>
</template>
</v-combobox>

Problem with expandable child component in parent v-data-table using Vuetify 2

I upgraded to Vuetify 2 from 1.5. Everything went pretty smoothly except for one thing. I have a parent component with a v-data-table and I want to pass data and expand each row with a child component.
ScanGrid(parent component):
<template>
<v-container>
<v-card>
<v-card-text>
<v-layout row align-center>
<v-data-table
:headers="headers"
:items="items"
:hide-default-footer="true"
item-key="id"
>
<template slot="items" slot-scope="props">
<tr #click="props.expanded = !props.expanded">
<td>{{ props.item.name }}</td>
<td class="text-xs-left large-column">
{{ props.item.scanned }}
</td>
<td class="text-xs-left large-column">
{{ props.item.incoming }}
</td>
<td class="text-xs-left large-column">
{{ props.item.outgoing }}
</td>
<td class="text-xs-left large-column">
{{ props.item.unknown }}
</td>
</tr>
</template>
<template slot="expand" slot-scope="props">
<ScanGridChild :value="props.item"></ScanGridChild>
</template>
</v-data-table>
</v-layout>
</v-card-text>
</v-card>
</v-container>
</template>
ScanGridChild(child component):
<template>
<v-card>
<v-card-text>{{ value }}</v-card-text>
</v-card>
</template>
<script>
export default {
name: "ScanGridChildComponent",
props: {
value: {
Type: Object,
Required: true
}
},
computed: {},
watch: {
props: function(newVal, oldVal) {
console.log("Prop changed: ", newVal, " | was: ", oldVal);
this.render();
}
}
};
</script>
<style></style>
It worked fine in Vuetify 1.5.19. I'm on Vuetify 2.1.6 and using single file components. Thanks.
Vuetify 2.x has major changes to many components, slot-scopes are replaced with v-slot, and many new properties and slots added to vuetify data table
Here is the working codepen reproduced the same feature with above code
https://codepen.io/chansv/pen/BaaWbKR?editors=1010
You need to make sure that you have vue js 2.x and vuetify 2.x
Parent component code:
<template>
<v-container>
<v-card>
<v-card-text>
<v-layout row align-center>
<v-data-table
:headers="headers"
:items="items"
item-key="name"
single-expand
:expanded="expanded"
hide-default-footer
#click:row="clickedRow"
>
<template v-slot:expanded-item="{ item }">
<td :colspan="headers.length">
<ScanGridChild :value="item"></ScanGridChild>
</td>
</template>
</v-data-table>
</v-layout>
</v-card-text>
</v-card>
</v-container>
</template>
<script>
export default {
...
data () {
return {
expanded: [],
headers: [
{
text: "Localisation",
sortable: true,
value: "name"
},
{
text: "Paquets scannés",
sortable: true,
value: "scanned"
},
{
text: "Paquets entrants",
sortable: true,
value: "incoming"
},
{
text: "Paquets sortants",
sortable: true,
value: "outgoing"
},
{
text: "Paquets inconnus",
sortable: true,
value: "unknown"
}
],
items: [
{
id: 1,
name: "Location 1",
scanned: 159,
incoming: 6,
outgoing: 24,
unknown: 4,
test: "Test 1"
},
{
id: 2,
name: "Location 2",
scanned: 45,
incoming: 6,
outgoing: 24,
unknown: 4,
test: "Test 2"
}
],
}
},
methods: {
clickedRow(value) {
if (this.expanded.length && this.expanded[0].id == value.id) {
this.expanded = [];
} else {
this.expanded = [];
this.expanded.push(value);
}
}
}
...
}
</script>
In child component
Replace
props: {
value: {
Type: Object,
Required: true
}
},
with( Type and Required change to lower case type and required)
props: {
value: {
type: Object,
required: true
}
},

Resources