In my Vue.js project I have a v-data-table.
If cell content is true I would like to replace with the green check_circle icon.
Why this code isn't working?
<template v-for="header in headers" v-slot:item[header.value]="{ item }">
<v-icon v-if="item[header.value]" color="green">check_circle</v-icon>
</template>
Now the table is:
EDIT 1
<v-data-table
:loading="loading"
:headers="headers"
:items="items"
:items-per-page="items_per_page"
:search="search"
no-data-text="Non ci sono elementi"
no-results-text="Non ci sono elementi filtrati"
loading-text="Caricamento in corso..."
:footer-props="footerProps"
class="elevation-1">
<template v-for="header in headers" v-slot:item[header.value]="{ item }">
<v-icon v-if="item[header.value]" color="green">check_circle</v-icon>
<v-icon v-else color="red">cancel</v-icon>
</template>
<template v-slot:item.actions="{ item }">
<v-icon
small
class="mr-2"
#click="editItem(item)"
>mdi-pencil</v-icon>
<v-icon
small
#click="deleteItem(item)"
>mdi-delete</v-icon>
</template>
<template v-slot:top>
<v-toolbar flat color="white">
<v-spacer></v-spacer>
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on }">
<v-btn color="primary" dark class="mb-2" #click="newItem" 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>
<!-- modifica elemento -->
<v-row v-if="editedIndex > -1">
<v-col v-for="(key,i) in keys_visible" :key="key" v-show="headers_visible[i].visible == true" cols="12" sm="6" md="4">
<v-text-field v-if="headers_visible[i].type == 'varchar'" v-model="editedItem[key]" :label="headers_visible[i].text" :disabled="!headers_visible[i].editable"></v-text-field>
<v-switch v-else-if="headers_visible[i].type == 'bit'" v-model="editedItem[key]" :label="headers_visible[i].text"></v-switch>
</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-toolbar>
</template>
<template v-slot:no-data>
<v-btn color="primary" #click="initialize">Reset</v-btn>
</template>
</v-data-table>
headers is like this:
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: 'Actions', value: 'actions', sortable: false },
]
a item is like this:
item: {
cleaned: true,
name: '',
usable: 0,
...
}
To iterate the headers dynamically for all items you'd need to use the body slot...
<template v-slot:body="{ items }">
<tr v-for="idx in items">
<td v-for="header in headers" class="text-left font-weight-black">
<v-icon v-if="idx[header.value]" color="green">check_circle</v-icon>
</td>
</tr>
</template>
Demo: https://codeply.com/p/W0vKEyRGRO
Also see: Vuetify Datatable - Enable content editing on all columns
Related
I'm complet stuck and can't see to fix my issue. My goal is to display the status of the toggle switch in my Vuetify data-table.
It seems to work but each time I change the toggle switch the status of all lines get changed. And this isn't the idea. It needs to be for each specific line.
Small side note: Instead of "true" and "false" I would prefer "On" and "off"
When you propose a solution, would you mind also telling me what I'm doing wrong as this is the only way I will learn.
<template>
<v-card>
<v-data-table :headers="headers" :items="companies">
<template v-slot:top>
<v-toolbar flat>
<v-dialog v-model="dialog" max-width="850px">
<template v-slot:activator="{on}">
<v-btn color="primary" dark class="mb-2" v-on="on">Nieuw bedrijf</v-btn>
</template>
<v-card>
<v-card-title>
<span class="headline">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col cols="12" sm="6" md="6">
<v-text-field v-model="editedItem.name" label="Bedrijfsnaam"></v-text-field>
</v-col>
</v-row>
<v-row>
<v-col cols="12" sm="6" md="6">
<v-switch v-model="switch1" flat :label="`Switch 1: ${switch1.toString()}`"></v-switch>
</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">Annuleer</v-btn>
<v-btn color="blue darken-1" text #click="save">Bewaar</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
<v-divider class="mt-3" />
</template>
<template v-slot:item.portaal="{}">
<v-chip color="primary" v-text="switch1" dark></v-chip>
</template>
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" #click="editItem(item)">mdi-pencil</v-icon>
<v-icon small text #click="showDeleteDialog(item)">mdi-delete</v-icon>
</template>
</v-data-table>
<v-dialog v-model="dialogDelete" max-width="500px">
<v-card>
<v-card-title>Delete</v-card-title>
<v-card-text>Weet je zeker dat je {{itemToDelete.name}} wenst te verwijderen?</v-card-text>
<v-card-actions>
<v-btn color="primary" text #click="dialogDelete = false">Annuleer</v-btn>
<v-btn color="primary" text #click="deleteItem()">Verwijderen</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-card>
</template>
Script
<script>
export default {
data: () => ({
headers: [
{ text: "Bedrijfsnaam", align: "start", value: "name" },
{ text: "Portaal", value: "portaal", sortable: false },
{ text: "Actions", value: "actions", sortable: false }
],
companies: [],
switch1: false,
dialog: false,
dialogDelete: false,
itemToDelete: {},
editedIndex: -1,
editedItem: {
name: ""
}
}),
computed: {
formTitle() {
return this.editedIndex === -1
? "Nieuw bedrijf"
: "Bewerk " + this.editedItem.name;
}
},
watch: {
dialog(val) {
val || this.close();
}
},
created() {
this.initialize();
},
methods: {
initialize() {
this.companies = [
{
name: "Bogaert SCA",
phone: "+32 50 64 68 62",
email: "marie34#daems.net",
website: "www.daems.net",
to: "http://www.bloomford.be",
location: "Brugge"
},
{
name: "Thomas BVBA",
phone: "+32 9 654 97 31 64",
email: "tess.claessens#charlier.org",
website: "www.charlier.org",
to: "http://www.rsca.be",
location: "Gent"
}
];
},
switch1(newValue) {
this.headers[5].value = newValue;
},
editItem(item) {
this.editedIndex = this.companies.indexOf(item);
this.editedItem = Object.assign({}, item);
this.dialog = true;
},
showDeleteDialog(item) {
this.itemToDelete = item;
this.dialogDelete = !this.dialogDelete;
},
deleteItem() {
const index = this.companies.indexOf(this.itemToDelete);
this.companies.splice(index, 1);
this.dialogDelete = false;
},
close() {
this.dialog = false;
setTimeout(() => {
this.editedItem = Object.assign({}, this.defaultItem);
this.editedIndex = -1;
}, 300);
},
save() {
if (this.editedIndex > -1) {
Object.assign(this.companies[this.editedIndex], this.editedItem);
} else {
this.companies.push(this.editedItem);
}
this.close();
}
}
};
</script>
You should bind the switch to portaal. Also switch1 should not be a method and a data property. The label doesn't have to be the same as the modal. just use a method for the on/off label...
<v-data-table :headers="headers" :items="companies">
<template v-slot:top>
<v-toolbar flat>
<v-dialog v-model="dialog">
<template v-slot:activator="{on}">
<v-btn color="primary" dark class="mb-2" v-on="on">Nieuw bedrijf</v-btn>
</template>
<v-card>
<v-card-title>
<span class="headline">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col cols="12" sm="6" md="6">
<v-text-field v-model="editedItem.name" label="Bedrijfsnaam"></v-text-field>
</v-col>
</v-row>
<v-row>
<v-col cols="12" sm="6" md="6">
<v-switch v-model="editedItem.portaal" flat :label="switchLabel(editedItem.portaal)"></v-switch>
</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">Annuleer</v-btn>
<v-btn color="blue darken-1" text #click="save">Bewaar</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
<v-divider class="mt-3" />
</template>
<template v-slot:item.portaal="{ item }">
<v-chip color="primary" v-text="switchLabel(item.portaal||false)" dark></v-chip>
</template>
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" #click="editItem(item)">mdi-pencil</v-icon>
<v-icon small text #click="showDeleteDialog(item)">mdi-delete</v-icon>
</template>
</v-data-table>
switchLabel (bool) {
return bool?'on':'off'
},
https://codeply.com/p/tlXizKP4dD
I'm learning a Vuetifyjs and try writing a "file explorer".
There is an example:
codepen-snippet
I can’t understand how to make sure that when you click on the right icon, the entry in the "tree" does not become "active".
Probably need to “stop” the events, but I don’t know how to do it.
Tell me.
Thank.
I want to click on this menu: Menu
it became like this: need
not like now: now
Snippet:
<div id="app">
<v-app id="inspire">
<v-content>
<v-container >
<v-layout justify-center>
<v-card min-width=400>
<v-treeview
v-model="tree"
:open="open"
:items="items"
activatable
hoverable
item-key="name"
open-on-click
>
<template v-slot:prepend="{ item, open }">
<v-icon v-if="!item.file">
{{ open ? 'mdi-folder-open' : 'mdi-folder' }}
</v-icon>
<v-icon v-else>
{{ files[item.file] }}
</v-icon>
</template>
<template v-slot:label="{item}">
<v-hover v-slot:default="{ hover }">
<div class="d-flex align-center">
<span>{{item.name}}</span>
<v-menu
class="ml-auto"
style="display: inline"
:nudge-width="200"
offset-y
>
<template v-slot:activator="{ on }">
<!--
-->
<v-btn
v-show="hover"
icon
small
v-on="on"
class="pa-0 ma-0"
>
<v-icon small class="pa-0 ma-0">more_vert</v-icon>
</v-btn>
</template>
<v-card>
<v-list>
<v-list-item #click="() => {}">
<v-list-item-action>
<v-icon>mdi-information-variant</v-icon>
</v-list-item-action>
<v-list-item-title>Info</v-list-item-title>
</v-list-item>
<v-list-item v-if="item.type === 'process' || item.type === 'state'" #click="() => {}">
<v-list-item-action>
<v-icon>power_settings_new</v-icon>
</v-list-item-action>
<v-list-item-title>Status</v-list-item-title>
</v-list-item>
<v-list-item #click="() => {}">
<v-list-item-action>
<v-icon>create</v-icon>
</v-list-item-action>
<v-list-item-title>Rename</v-list-item-title>
</v-list-item>
<v-list-item #click="() => {}">
<v-list-item-action>
<v-icon>file_copy</v-icon>
</v-list-item-action>
<v-list-item-title>Copy</v-list-item-title>
</v-list-item>
<v-list-item #click="() => {}">
<v-list-item-action>
<v-icon>mdi-folder-plus</v-icon>
</v-list-item-action>
<v-list-item-title>Create folder</v-list-item-title>
</v-list-item>
<v-list-item #click="() => {}">
<v-list-item-action>
<v-icon>delete</v-icon>
</v-list-item-action>
<v-list-item-title>Delete</v-list-item-title>
</v-list-item>
</v-list>
</v-card>
</v-menu>
</div>
</v-hover>
</template
</v-treeview>
</v-card
</v-layout justify-center>
</v-container>
</v-content>
</v-app>
</div>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
open: ['public'],
files: {
html: 'mdi-language-html5',
js: 'mdi-nodejs',
json: 'mdi-json',
md: 'mdi-markdown',
pdf: 'mdi-file-pdf',
png: 'mdi-file-image',
txt: 'mdi-file-document-outline',
xls: 'mdi-file-excel',
},
tree: [],
items: [
{
name: '.git',
},
{
name: 'node_modules',
},
{
name: 'public',
children: [
{
name: 'static',
children: [{
name: 'logo.png',
file: 'png',
}],
},
{
name: 'favicon.ico',
file: 'png',
},
{
name: 'index.html',
file: 'html',
},
],
},
{
name: '.gitignore',
file: 'txt',
},
{
name: 'babel.config.js',
file: 'js',
},
{
name: 'package.json',
file: 'json',
},
{
name: 'README.md',
file: 'md',
},
{
name: 'vue.config.js',
file: 'js',
},
{
name: 'yarn.lock',
file: 'txt',
},
],
}),
})
What is happening here is that your click event is propagating to its parent element, so when you click on the icon to display the menu it also triggers the click event of your parent element which is the file or folder container.
You can add #click.stop to your v-btn in line 44, like this:
<template v-slot:activator="{ on }">
<!--
-->
<v-btn
v-show="hover"
icon
small
v-on="on"
class="pa-0 ma-0"
#click.stop
>
<v-icon small class="pa-0 ma-0">more_vert</v-icon>
</v-btn>
</template>
This will stop the event from propagating to its parent element, you can try it out here: codepen-snippet
Now when you click the button it will display your menu and won't change the active or inactive state on your files or folders.
To remove the blue highlighting of items when clicked, remove "activatable" from the v-treeview component:
<v-treeview
v-model="tree"
:open="open"
:items="items"
activatable
hoverable
item-key="name"
open-on-click >
My vue component like this :
<template>
<v-row>
<v-col cols="12" sm="6" md="4">
<v-dialog
v-for="(item, i) in test" :key="i"
ref="dialog"
v-model="modal"
:return-value.sync="item.date"
persistent
width="290px"
>
<template v-slot:activator="{ on }">
<v-text-field
v-model="item.date"
label="Picker in dialog"
prepend-icon="event"
readonly
v-on="on"
></v-text-field>
</template>
<v-date-picker v-model="date" scrollable>
<div class="flex-grow-1"></div>
<v-btn text color="primary" #click="modal = false">Cancel</v-btn>
<v-btn text color="primary" #click="$refs.dialog.save(item.date)">OK</v-btn>
</v-date-picker>
</v-dialog>
</v-col>
</v-row>
</template>
<script>
export default {
data: () => ({
test: [
{ id: 1, date: new Date().toISOString().substr(0, 10) },
{ id: 2, date: new Date().toISOString().substr(0, 10) },
],
modal: false,
}),
}
</script>
multiple datetimepicker doesn't work properly
if i click ok button in the modal, there exist error like this :
[Vue warn]: Error in v-on handler: "TypeError: _vm.$refs.dialog.save is not a function"
How can I solve this problem?
First off, you need to return the whole object from the dialog, not just the date. With :return-value.sync="item.date", the objects in test will have only date as their only property. Your date picker also has a wrong binding.
<v-dialog
v-for="(item, i) in test" :key="i"
ref="dialog"
v-model="modal"
:return-value.sync="item"
persistent
width="290px"
>
<template v-slot:activator="{ on }">
<v-text-field
v-model="item.date"
label="Picker in dialog"
prepend-icon="event"
readonly
v-on="on"
></v-text-field>
</template>
<v-date-picker v-model="item.date" scrollable>
<div class="flex-grow-1"></div>
<v-btn text color="primary" #click="modal = false">OK</v-btn>
</v-date-picker>
</v-dialog>
I would like have my data table mask the "Password" entries (both in the table and in the dialog). This page is supposed to be an admin control panel for account management. I checked the documentation and can't figure out how to do it.
I tried using "mask" for text-fields, but to no avail.
<template>
<v-app>
<v-content>
<div>
<v-toolbar flat color="white">
<v-toolbar-title>Accounts:</v-toolbar-title>
<v-spacer></v-spacer>
<v-flex md4 mt-3>
<v-text-field browser-autocomplete height="20px" full-width class="mx-3" flat label="Search" prepend-inner-icon="search" outline></v-text-field>
</v-flex>
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on }">
<v-btn color="success" dark class="mb-2" v-on="on">Add Account</v-btn>
</template>
<v-card>
<v-card-title>
<span class="headline">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container grid-list-xs>
<v-layout>
<v-flex xs12 sm6 md8>
<v-text-field v-model="editedItem.orgname" label="Organization Name"></v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 md8>
<v-text-field v-model="editedItem.orgusername" label="Organization Username"></v-text-field>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm6 md8>
<v-text-field v-model="editedItem.password" label="Password"></v-text-field>
</v-flex>
</v-layout>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" flat #click="close">Cancel</v-btn>
<v-btn color="blue darken-1" flat #click="save">Save</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
<v-data-table :headers="headers" :items="orgname" class="elevation-1">
<template v-slot:items="props">
<td>{{ props.item.orgname }}</td>
<td class="text-xs-left">{{ props.item.orgusername }}</td>
<td class="text-xs-left">{{ props.item.password }}</td>
<td class="justify-center layout px-0">
<v-icon small class="mr-2" #click="editItem(props.item)">
edit
</v-icon>
<v-icon small #click="deleteItem(props.item)" >
delete
</v-icon>
</td>
</template>
</v-data-table>
</div>
</v-content>
</v-app>
</template>
The script
<script>
export default{
data: () => ({
dialog: false,
headers: [
{
text: 'Organization Name',
align: 'left',
sortable: true,
value: 'orgname'
},
{ text: 'Organization Username', value: 'orgusername' , sortable: false},
{ text: 'Organization Password', value: 'password', sortable: false },
],
orgname: [],
editedIndex: -1,
editedItem: {
orgname: '',
orgemail: '',
password: ''
},
defaultItem: {
orgname: '',
orgemail: '',
password: ''
}
}),
computed: {
formTitle () {
return this.editedIndex === -1 ? 'Add Account' : 'Edit Info'
}
},
watch: {
dialog (val) {
val || this.close()
}
},
created () {
this.initialize()
},
methods: {
initialize () {
this.orgname = [
{
orgname: 'Student Organization',
orgusername:'studorganization',
password: 'studorganization'
}
]
},
editItem (item) {
this.editedIndex = this.orgname.indexOf(item)
this.editedItem = Object.assign({}, item)
this.dialog = true
},
deleteItem (item) {
const index = this.orgname.indexOf(item)
confirm('Are you sure you want to delete this?') && this.orgname.splice(index, 1)
},
close () {
this.dialog = false
setTimeout(() => {
this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1
}, 300)
},
save () {
if (this.editedIndex > -1) {
Object.assign(this.orgname[this.editedIndex], this.editedItem)
} else {
this.orgname.push(this.editedItem)
}
this.close()
}
}
}
</script>
I expected it to be masked with asterisks (*), but I don't know how. (it's currently in plain text).
You can use type="password" in v-text-field
<v-text-field
v-model="editedItem.password" label="Password"
type="password">
</v-text-field>
If you want toggle password visibility on/off, you can add append-icon and a data attribute:
data() {
return {
showPassword: false
}
}
<v-text-field
v-model="editedItem.password" label="Password"
:type="showPassword ? 'text' : 'password'"
:append-icon="showPassword ? 'visibility' : 'visibility_off'"
#click:append="showPassword = !showPassword"
type="password">
</v-text-field>
In data table, if you want to hide password, just replace it with some dummy text. Change
<td class="text-xs-left">{{ props.item.password }}</td>
to
<td class="text-xs-left">********</td>
You can check password example in Vuetify document
How Do I resolve this. I am getting the error Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. This error is being printed on the console as I run the app. When it does this , the nothing is displayed on on the views its just blank.
<template>
<v-container id="dashboard" fluid grid-list-lg class="mx- pa-7">
<v-layout row wrap>
<v-flex md3 sm6 xs12>
<v-card class="cyan darken-3" l light>
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">Income Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalUsers}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
<v-flex md3 sm6 xs12>
<v-card class="blue-grey darken-1">
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">Today's Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalAmount}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
<v-flex md3 sm6 xs12>
<v-card class="pink lighten-4">
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">Yesterday's Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalUsersThis}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
<v-flex md3 sm6 xs12>
<v-card class="blue-grey darken-1">
<v-container fluid grid-list-sm light>
<v-layout class="mt-0 mb-0" row wrap>
<v-flex d-flex xs3>
<v-icon class="mx-0" x-large light>beenhere</v-icon>
</v-flex>
<v-flex d-flex xs9 >
<v-layout class="mt-2 mb-0 pa-0" row wrap>
<x-flex d-flex xs12>
<div class="silver--text subheading">This Week's Revenue</div>
</x-flex>
<v-flex d-flex xs12>
<div class="silver--text display-1">{{totalAmountThis}}</div>
<v-btn outline class="darkgrey--text darken-1" right flat small>More</v-btn>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-flex>
</v-layout>
<v-layout class="pt-1" row wrap>
<v-flex md4 xs12>
<v-card light>
<doughnut></doughnut>
</v-card>
</v-flex>
<v-flex md4 xs12>
<v-card light>
<bar></bar>
</v-card>
</v-flex>
<v-flex md4 xs12>
<v-card light class="Chart">
<line-chart></line-chart>
</v-card>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs7>
<v-card>
<v-card-title>
Recent Transactions
<v-spacer/> <v-spacer/>
<v-text-field name="product" label="Search" light v-model="searchTransaction"></v-text-field>
</v-card-title>
<v-data-table v-bind:headers="headers" v-bind:items="items" v-bind:search="search"
v-bind:pagination.sync="pagination" hide-actions
class="elevation-1">
<template slot="items" slot-scope="props" class="body-2" >
<td class="body-2" >{{ props.item.account_from }}</td>
<td class="text-xs-left">{{ props.item.amount }}</td>
<td class="text-xs-left">{{ props.item.transaction_code}}</td>
<td class="text-xs-left">{{ props.item.payment_mode}}</td>
<td class="text-xs-left">{{ props.item.ref}}</td>
<td class="text-xs-left">{{ props.item.status}}
</td>
<td class="text-xs-left">{{ props.item.date}}</td>
<!-- <td class="text-xs-left">{{ props.item.quantity}}</td>
<td class="text-xs-left"><img :src='getImageURL(props.item.Product.phone_number)' height="90dp" width="90dp"/></td>
<td class="text-xs-left">
<v-btn fab small dark class="teal" #click.native="edit()">
<v-icon>edit</v-icon>
</v-btn>
<v-btn fab small class="cyan" #click.native="remove(props.item)">
<v-icon>delete</v-icon>
</v-btn>
</td>-->
</template>
</v-data-table>
<div class="text-xs-center pt-2">
<v-pagination v-model="pagination.page" :length="pages" circle></v-pagination>
</div>
</v-card>
</v-flex>
<v-flex xs5>
<v-card>
<v-card-title>
Merchants
<v-spacer/> <v-spacer/>
<v-text-field name="product" label="Search" light v-model="productSearch"></v-text-field>
</v-card-title>
<v-data-table v-bind:headers="headers2" v-bind:items="businesses" v-bind:search="search"
v-bind:pagination.sync="pagination2" hide-actions
class="elevation-1"
:loading="false">
<v-progress-linear slot="progress" color="blue" indeterminate></v-progress-linear>
<template slot="items" slot-scope="props" class="body-2" >
<td class="body-2" >{{ props.item.business_name }}</td>
<td class="text-xs-left">{{ props.item.short_code }}</td>
<td class="text-xs-left">{{ props.item.sender_id}}</td>
<!--<td class="text-xs-left">{{ props.item.payment_mode}}</td>
<td class="text-xs-left">KES {{ props.item.transaction_ref}}</td>
<td class="text-xs-left">KES {{ props.item.date}}</td>-->
<!-- <td class="text-xs-left">{{ props.item.quantity}}</td>
<td class="text-xs-left"><img :src='getImageURL(props.item.Product.phone_number)' height="90dp" width="90dp"/></td>
<td class="text-xs-left">
<v-btn fab small dark class="teal" #click.native="edit()">
<v-icon>edit</v-icon>
</v-btn>
<v-btn fab small class="cyan" #click.native="remove(props.item)">
<v-icon>delete</v-icon>
</v-btn>
</td>-->
</template>
</v-data-table>
<div class="text-xs-center pt-2">
<v-pagination v-model="pagination2.page" :length="pages2" circle></v-pagination>
</div>
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import Bar from "../components/chart/Bar";
import Doughnut from "../components/chart/Doughnut";
import LineChart from "../components/chart/LineChart";
import { execute } from '../api'
export default {
name: "Dashboard",
components: {
Bar,
Doughnut,
LineChart
},
data () {
return {
searchTransaction:'',
items:[],
businesses:[],
totalUsers:'',
totalAmount:'',
totalUsersThis:'',
totalAmountThis:'',
search: '',
pagination: [],
pagination2: [],
productSearch:'',
headers: [
{
text: 'Phone Number',
left: true,
sortable: false,
value: 'phone_number'
},
{ text: 'Amount', value: 'amount' , sortable: false,},
{ text: 'Transaction Code', value: 'transaction_code' , sortable: false,},
{ text: 'Payment Mode', value: 'payment_mode' , sortable: false},
{ text: 'Transaction ref', value: 'transaction_ref' , sortable: false},
{ text: 'Status', value: 'status' , sortable: false},
{ text: 'date', value: 'date' , sortable: false}
], headers2: [
{
text: 'Business',
left: true,
sortable: false,
value: 'business'
},
{ text: 'ShortCode', value: 'short_code' , sortable: false,},
{ text: 'Sender ID', value: 'sender_id' , sortable: false,},
]
};
},
watch: {
searchTransaction: function() {
this.getTransactions();
}
},
methods: {
getCustomers () {
const data = new FormData()
data.append('TransactionType', 'getDashboardData')
execute(data).then((res) => {
this.totalUsers= new Intl.NumberFormat().format(res.data.data.IncomeRevenue)
this.totalAmount= new Intl.NumberFormat().format(res.data.data.TodayRevenue)
this.totalUsersThis= new Intl.NumberFormat().format(res.data.data.YesterdayRevenue)
this.totalAmountThis= new Intl.NumberFormat().format(res.data.data.ThisWeekRevenue)
}).catch((e) => {
// TODO
})
},
getTransactions () {
const data = new FormData()
data.append('TransactionType', 'getRecentTransactions')
data.append('keyword',this.searchTransaction)
execute(data).then((res) => {
this.items = res.data.data
}).catch((e) => {
// TODO
})
}, getBusinesses () {
const data = new FormData()
data.append('TransactionType', 'getBusinesses')
execute(data).then((res) => {
this.businesses = res.data.data
}).catch((e) => {
// TODO
})
}
},
computed: {
pages () {
return this.pagination && this.pagination.rowsPerPage ? Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage) : 0
},
pages2 () {
return this.pagination2 && this.pagination2.rowsPerPage ? Math.ceil(this.pagination2.totalItems / this.pagination2.rowsPerPage) : 0
}
},
mounted () {
this.getCustomers()
this.getTransactions()
this.getBusinesses()
}
};
</script>
<!--<style scoped>
#dashboard .flex {
margin-bottom: 2px;
}
</style>-->
Since you're using lots of <v-flex> elements in your code, my guess is you just made a typo and accidentally created a <x-flex> element. Just fix the typo (change all the x-flex to v-flex in your code) and it will work