Related
I am a beginner in Vue.js and Vuetify:
I have a Vuetify data table and I am trying to append different icons (customized icons from flaticon) to just the column for example "fat (g)". Means every new line has it's own icon.
Moreover I like to have a title instead of the checkmark in the v-table-header.
How can I do this in the following code?
Example code:
https://github.com/vuetifyjs/vuetify/blob/master/packages/docs/src/examples/v-data-table/prop-row-selection.vue:
<template>
<div id="app">
<v-app id="inspire">
<v-data-table
v-model="selected"
:headers="headers"
:items="desserts"
:single-select="singleSelect"
item-key="name"
show-select
class="elevation-1"
>
<template v-slot:top>
<v-switch
v-model="singleSelect"
label="Single select"
class="pa-3"
></v-switch>
</template>
</v-data-table>
</v-app>
</div>
</template>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
singleSelect: false,
selected: [],
headers: [
{
text: 'Dessert (100g serving)',
align: 'start',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
],
}
},
})
</script>
Check this codesanbox I made: https://codesandbox.io/s/stack-70958304-brw8z?file=/src/components/AppendIcons.vue
Well it depends, how do you want to decide what icon use for each row. The normal aproach would be to have the desired icon name within your data array.
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
icon: 'home'
},
...
]
Now to append the icon to the fat(g) column can be done using the item slot of your v-data-table. In my example I used the #item.fat="{item}" which is a shortand for v-slot:item.fat="{item}" to modify the content of the fat column. For more info about slots check the documentation page.
If you're using es-lint you might encounter a warning mention something about the valid-v-slot rule, this is a known false positive that you can read more about in this GitHub issue thread, I personally just turn that es-lint rule off.
<v-data-table
v-model="selected"
:headers="headers"
:items="desserts"
item-key="name"
show-select
class="elevation-1"
>
<template v-slot:top>
<div class="my-2 mx-4 text-h5 font-weight-medium">
My custom title
</div>
</template>
<template #item.fat="{item}">
<div class="d-flex">
<div>
{{ item.fat }}
</div>
<div class="ml-2">
<i :class="`fi fi-rr-${item.icon}`"></i>
</div>
</div>
</template>
</v-data-table>
UPDATE 1: Import flaticon through CDN.
<style>
/* <style> blocks that doesn't have the 'scoped' attribute
make the CSS available in all your components, I usually put
my global CSS in the App.vue file or in a external css file.
In this case I'm just importing the regular rounded style
of flaticons, if you want to use bold, solid, straight icons
you'll need to import those as well */
#import url("https://cdn-uicons.flaticon.com/uicons-regular-rounded/css/uicons-regular-rounded.css");
i {
font-size: 1.2em;
}
</style>
Vuetify components use material icons by default inside of them, in case you want to go one step further and modify those icons to use flaticons. Instead of creating a wrapper component or manually defining the specific icon each time a component appears, you can configure it at a global level, see Icons Font docs for more info.
Let's say you want to modify the sort arrow icon used in vuetify components to use the arrow-small-up flaticon. Then you would do something like this:
// src/plugins/vuetify.js
import Vue from "vue";
import Vuetify from "vuetify";
import "vuetify/dist/vuetify.min.css";
Vue.use(Vuetify)
export default new Vuetify({
icons: {
values: {
sort: "fi fi-rr-arrow-small-up"
},
},
})
UPDATE 2: How to use custom SVG files in vuetify.
Local SVG files can be displayed in your applicaction by simply using the normal <img> tag. Vuetify's <v-img> component can only display external SVG files that comes from an URL. Like this one right here: https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg
That's because the internal fileloader that use <v-img> doesn't support local SVG files. So the simplest solution is just use the normal <img> tag.
<div>
{{ item.fat }}
</div>
<div class="ml-2">
<img v-if="item.name == 'Donut'" src="../assets/donut.svg" width="20" alt=""/>
<i v-else :class="`fi fi-rr-${item.icon}`"></i>
</div>
Hello how to changes this values in data table, true change to active or false in inactive
add my code in vue js and vuetify i like change value in row state, chage this value true change to active or false in inactive, i'm using axios to connect in api from csharp
next of code i'm add image of i want made it this
<template>
<v-data-table
:headers="headers"
:items="categories"
sort-by="Name"
class="elevation-1"
:search="search"
>
<template v-slot:top>
<v-toolbar flat>
<v-toolbar-title>Categories</v-toolbar-title>
<v-divider class="mx-4" inset vertical></v-divider>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="search"
label="Search"
single-line
hide-details
></v-text-field>
<v-spacer></v-spacer>
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on, attrs }">
<v-btn color="primary" dark class="mb-2" v-bind="attrs" v-on="on">
New Item
</v-btn>
</template>
<v-card>
<v-card-title>
<span class="text-h5">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col cols="12" sm="6" md="4">
<v-text-field
v-model="editedItem.namecategory"
label="Name"
></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field
v-model="editedItem.descategory"
label="Description"
></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field
v-model="editedItem.numberstatate"
label="State"
></v-text-field>
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text #click="close"> Cancel </v-btn>
<v-btn color="blue darken-1" text #click="save"> Save </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="dialogDelete" max-width="500px">
<v-card>
<v-card-title class="text-h5"
>Are you sure you want to delete this item?</v-card-title
>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text #click="closeDelete"
>Cancel</v-btn
>
<v-btn color="blue darken-1" text #click="deleteItemConfirm"
>OK</v-btn
>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
</template>
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" #click="editItem(item)"> edit </v-icon>
<v-icon small #click="deleteItem(item)"> delete </v-icon>
</template>
<template v-slot:no-data>
<v-btn color="primary" #click="initialize"> Reset </v-btn>
</template>
<script>
import axios from "axios";
export default {
data: () => ({
categories: [],
search: "",
dialog: false,
dialogDelete: false,
headers: [
{ text: "Actions", value: "actions", sortable: false},
{ text: "Name", value: "namecategory" },
{ text: "Description", value: "descategory", sortable: false },
{ text: "State", value: "numberstatate" , sortable: false},
],
desserts: [],
editedIndex: -1,
editedItem: {
name: "",
calories: 0,
fat: 0,
carbs: 0,
protein: 0,
},
defaultItem: {
name: "",
calories: 0,
fat: 0,
carbs: 0,
protein: 0,
},
}),
computed: {
formTitle() {
return this.editedIndex === -1 ? "New Item" : "Edit Item";
},
},
watch: {
dialog(val) {
val || this.close();
},
dialogDelete(val) {
val || this.closeDelete();
},
},
created() {
this.initialize();
this.tolist();
},
methods: {
tolist() {
let me = this;
axios
.get("api/categories/tolist/")
.then(function (response) {
me.categories = response.data;
//console.log(response)
})
.catch(function (error) {
console.log(error);
});
},
initialize() {
this.desserts = [
{
name: "Frozen Yogurt",
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
},
{
name: "Ice cream sandwich",
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
},
{
name: "Eclair",
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
},
{
name: "Cupcake",
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
},
{
name: "Gingerbread",
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
},
{
name: "Jelly bean",
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
},
{
name: "Lollipop",
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
},
{
name: "Honeycomb",
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
},
{
name: "Donut",
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
},
{
name: "KitKat",
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
},
];
},
editItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialog = true;
},
deleteItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialogDelete = true;
},
deleteItemConfirm() {
this.desserts.splice(this.editedIndex, 1);
this.closeDelete();
},
close() {
this.dialog = false;
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
});
},
closeDelete() {
this.dialogDelete = false;
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
});
},
save() {
if (this.editedIndex > -1) {
Object.assign(this.desserts[this.editedIndex], this.editedItem);
} else {
this.desserts.push(this.editedItem);
}
this.close();
},
},
};
</script>
and my view is this
enter image description here
I have solved it in the following way, add next line after of data-table
<template v-slot:item.numberstatate="{ item }">
<span v-if="item.numberstatate" class="blue--text">Active</span>
<span v-else class="red--text">insactive</span>
</template
So that it is as follows:
<v-data-table
:headers="headers"
:items="categories"
sort-by="Name"
class="elevation-1"
:search="search"
>
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" #click="editItem(item)"> edit </v-icon>
<v-icon small #click="deleteItem(item)"> delete </v-icon>
</template> ........
I am looking at the vuetify table example for CRUD operations. A codepen for it is here:
https://codepen.io/uglyhobbitfeet/pen/oNvKaaL
I added a parent form that wraps around the table and another component. It validates that the table has more than 0 rows and validates the other component before the user can click the 'continue' button.
In the provided codepen, when the user clicks on the 'New Item' button (located at the top-right of the table), I would like to validate the popped up fields before the user can 'save' the data to the table. How would that be done? I have tried to wrap the v-dialog in a separate v-form from the parent form, but I couldn't get it to work and I'm not sure nesting forms is the way to go. Any suggestions?
Since SO requires code to be posted when providing a codepen link here's a small snippet.
<v-data-table
:headers="headers"
:items="desserts"
sort-by="calories"
class="elevation-1"
>
reassignFormInputs(form) {
const inputs = [];
// Copied from VForm's previous life* which had a getInputs() function
const search = (children, depth = 0) => {
for (let index = 0; index < children.length; index++) {
const child = children[index];
if (child.errorBucket !== undefined) inputs.push(child);
else search(child.$children, depth + 1);
}
if (depth === 0) return inputs;
};
search(form.$children);
form.inputs = inputs;
},
saveForm() {
this.reassignFormInputs(this.$refs.form);
if (this.valid) {
console.log(this.lessonPlanData);
} else {
this.$refs.form.validate();
}
},
Assign your child components to the parent input.
Source: https://github.com/vuetifyjs/vuetify/issues/4900#issuecomment-423600028
I get your code and make some changes, I added the v-form inside de v-container to validate, then I created the Rules for the inputs to validate, and disabled the button if the form is not valid for both editing and new items.
In the second part the script I added the rules to validate the fields and then in the save function I check if everything is ok.
In the other form (father form) you can just verify if some item was added since you already validated the data inside the form in the dialog.
this.desserts.length > 0 //And then proceed
For more info see the docs
Template
<div id="app">
<v-app id="inspire">
<v-data-table
:headers="headers"
:items="desserts"
sort-by="calories"
class="elevation-1"
>
<template v-slot:top>
<v-toolbar flat color="white">
<v-toolbar-title>My CRUD</v-toolbar-title>
<v-divider
class="mx-4"
inset
vertical
></v-divider>
<div class="flex-grow-1"></div>
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on }">
<v-btn color="primary" dark class="mb-2" v-on="on">New Item</v-btn>
</template>
<v-card>
<v-card-title>
<span class="headline">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<!-- Form Tag -->
<v-form
id="dessertForm"
ref="dessertForm"
v-model="isValid"
>
<v-row>
<v-col cols="12" sm="6" md="4">
<v-text-field :rules="nameRules" v-model="editedItem.name" label="Dessert name"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field :rules="genericRules" v-model="editedItem.calories" label="Calories"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field :rules="genericRules" v-model="editedItem.fat" label="Fat (g)"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field :rules="genericRules" v-model="editedItem.carbs" label="Carbs (g)"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field :rules="genericRules" v-model="editedItem.protein" label="Protein (g)"></v-text-field>
</v-col>
</v-row>
</v-form>
</v-container>
</v-card-text>
<v-card-actions>
<div class="flex-grow-1"></div>
<v-btn color="blue darken-1" text #click="close">Cancel</v-btn>
<!-- Disable button if is not valid -->
<v-btn :disabled="!isValid" color="blue darken-1" text #click="save">Save</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
</template>
<template v-slot:item.action="{ item }">
<v-icon
small
class="mr-2"
#click="editItem(item)"
>
edit
</v-icon>
<v-icon
small
#click="deleteItem(item)"
>
delete
</v-icon>
</template>
<template v-slot:no-data>
<v-btn color="primary" #click="initialize">Reset</v-btn>
</template>
</v-data-table>
</v-app>
</div>
Script
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
dialog: false,
isValid: true,
// Rules for name (example)
nameRules: [
v => !!v || 'Name is required',
v => (v && v.length >= 10) || 'Name must be more than 10 characters',
],
// Rules for generic fields (example)
genericRules: [
v => (v && v > 0) || 'Value must be more than 0',
],
headers: [
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Actions', value: 'action', sortable: false },
],
desserts: [],
editedIndex: -1,
editedItem: {
name: '',
calories: 0,
fat: 0,
carbs: 0,
protein: 0,
},
defaultItem: {
name: '',
calories: 0,
fat: 0,
carbs: 0,
protein: 0,
},
}),
computed: {
formTitle () {
return this.editedIndex === -1 ? 'New Item' : 'Edit Item'
},
},
watch: {
dialog (val) {
val || this.close()
},
},
mounted () {
this.initialize()
},
methods: {
initialize () {
this.desserts = [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
},
]
},
editItem (item) {
this.editedIndex = this.desserts.indexOf(item)
this.editedItem = Object.assign({}, item)
this.dialog = true
},
deleteItem (item) {
const index = this.desserts.indexOf(item)
confirm('Are you sure you want to delete this item?') && this.desserts.splice(index, 1)
},
close () {
this.dialog = false
setTimeout(() => {
this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1
}, 300)
},
save () {
if(this.$refs.dessertForm.validate()) {
if (this.editedIndex > -1) {
Object.assign(this.desserts[this.editedIndex], this.editedItem)
} else {
this.desserts.push(this.editedItem)
}
this.close()
}
},
},
})
It looks like I did get it working with nested v-forms. I updated the codepen to show the solution. If you edit a row and remove the dessert name the save button will be disabled. If there are no table rows or the other v-text-field has no text the continue button will be disabled.
I am currently trying to pull in the datatable row info into a dialog for the rows with qty input value greater than 0. I know with checkboxes if selected/true, it pulls all the same row information into a selected array to easily use. I'm trying to get this same functionality for input greater than 0.
Got checked boxes row info to get into dialog by using the selected array. Cant seem to figure out how to do the same (get that rows data) with inputs greater than 0
https://codepen.io/anon/pen/xeVZKv?editors=1010
HTML
<div id="app">
<v-app id="inspire">
<v-data-table
:headers="headers"
:items="desserts"
class="elevation-1"
v-model="selected"
item-key="name"
>
<template v-slot:items="props">
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
<td class="text-xs-right">{{ props.item.carbs }}</td>
<td class="text-xs-right">{{ props.item.protein }}</td>
<td v-if="props.item.qty < 2" style="width: 10%">
<v-checkbox v-model="props.selected" primary hide-details></v-checkbox>
</td>
<td v-else style="display:inline-flex;">
<v-text-field
value="0"
onclick="this.select()"
type= "number"
:max="props.item.Qty"
:totalCount="props.item.Qty"
min="0"
:id="'inputCount' + props.index"
style="width:40px; margin-left: 5px;"
#change="counter()"
></v-text-field>
<div style="padding-top: 15px; margin-left: 10px;">of {{ props.item.qty }}</div>
</td>
</template>
<template v-slot:pageText="props">
Lignes {{ props.pageStart }} - {{ props.pageStop }} de {{ props.itemsLength }}
</template>
</v-data-table>
<v-layout row wrap class="">
<v-flex xs4 class="text-xs-left">
</v-flex>
<v-flex xs4 class="text-xs-center">
</v-flex>
<v-flex xs4 class="text-xs-right">
<v-btn v-if="buyCounter < 1" color="primary" class="receiveButton" :disabled="buttonActivate" #click="buyModel()">Receive</v-btn>
<v-btn v-else-if="buyCounter > 0 && buyCounter < 2" color="primary" class="receiveButton" :disabled="buttonActivate" #click="buyModel()">Receive {{ buyCounter }} Part</v-btn>
<v-btn v-else-if="buyCounter > 1" color="primary" class="receiveButton" :disabled="buttonActivate" #click="buyModel()">Receive {{ buyCounter }} Parts</v-btn>
<v-btn v-else color="primary" class="receiveButton" :disabled="buttonActivate">Receive</v-btn>
</v-flex>
</v-layout>
</v-app>
</div>
JS
new Vue({
el: '#app',
data () {
return {
inputCount: 0,
selected: [],
headers: [
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name'
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Qty Available', value: 'qty' }
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
qty: 1
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
qty: 2
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
qty: 1
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
qty: 1
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
qty: 3
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
qty: 1
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
qty: 1
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
qty: 1
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
qty: 1
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
qty: 1
}
]
};
},
computed: {
buttonActivate: function () {
let count = 0;
$('input[id^="inputCount"]').each(function (i, e) {
let element = $(e).val();
if (element == "") {
element = 0;
}
let eachCountInt = parseInt(element);
count = eachCountInt + count;
})
this.inputCount = count;
if (this.selected.length > 0 || this.inputCount > 0) {
return false;
} else {
return true;
}
},
buyCounter: function () {
let count = this.selected.length + this.inputCount;
return count;
}
},
methods: {
counter() {
let count = 0;
$('input[id^="inputCount"]').each(function (i, e) {
let element = $(e).val();
if (element == "") {
element = 0;
}
let eachCountInt = parseInt(element);
count = eachCountInt + count;;
})
this.inputCount = count;
},
buyModel() {
}
}
})
Overall looking to pull in all selected/greater than 0 info into the dialog to confirm before processing. Any help would be greatly appreciated.
Is it possible to left align the rows per pages and page navigation and put a button in its place in the same row?
The actions row are aligned right by default. There is a way to achieve what you want though. You can use custom pagination and hide the current one:
<v-data-table
:headers="headers"
:items="desserts"
:search="search"
hide-actions
:pagination.sync="pagination"
>
And add this after the datatable:
<v-layout row justify-center>
<v-pagination v-model="pagination.page" :length="pages"></v-pagination>
<v-btn class="test">test</v-btn>
</v-layout>
See more here.
Here is a Codepen in action.
I found the easiest way is to add the button to some data table slot you use and just position the button relatively to the table.
<v-data-table
style="position: relative;">
<template slot="footer">
<v-btn style="position: absolute; left: 10px; bottom: 10px;">
test
</v-btn>
</template>
</v-data-table>
Simplest way by CSS :
template in your datatable :
<template v-slot:actions-prepend>
<v-btn>
Click me !
</v-btn>
</template>
CSS :
.my-grid .v-datatable__actions > div:first-child {
flex: 1;
}
Working snippet :
new Vue({
el: '#app',
methods: {
onClick() { this.dark = !this.dark; }
},
data: {
dark: true,
headers: [{
text: 'Dessert (100g serving)',
value: 'name'
},
{
text: 'Calories',
value: 'calories'
},
{
text: 'Fat (g)',
value: 'fat'
},
{
text: 'Carbs (g)',
value: 'carbs'
},
{
text: 'Protein (g)',
value: 'protein'
},
{
text: 'Iron (%)',
value: 'iron'
}
],
desserts: [{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%'
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%'
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%'
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%'
}
]
}
})
.my-grid .v-datatable__actions > div:first-child {
flex: 1;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#1.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#1.x/dist/vuetify.js"></script>
<div id="app">
<v-app :dark="dark">
<v-content>
<v-data-table :headers="headers" :items="desserts" class="my-grid">
<template v-slot:items="{item}">
<tr>
<td>{{item.name}}</td>
<td>{{item.calories}}</td>
<td>{{item.fat}}</td>
<td>{{item.carbs}}</td>
<td>{{item.protein}}</td>
<td>{{item.iron}}</td>
</tr>
</template>
<template v-slot:actions-prepend>
<v-btn #click="onClick">
Switch mode
</v-btn>
</template>
</v-data-table>
</v-content>
</v-app>
</div>