Vuetify complex v-data-table based component for server requests ✨
Use for easy server requests. Just pass your api methods and headers to component and use!
Use for CRUD server models
- Server change pagination, sort, perpage - Just pass api methods
- Settings module - Reorder, pin and hide colums. And it will be cached to local storage.
- Add custom search field - Pass your own search fields via slots
- Inludes all features VApiDatatable
- Create object - Pass your create(POST) method to method-create prop
- Delete object - Pass your delete(DELETE) method to method-delete prop
- Update object - Pass your update(PUT) method to method-update prop
- Vee-validate 3.x
- Vuetify 2.x (only with vuetify-loader)
- Vue 2.x
npm install --save v-api-datatable
or
yarn add v-api-datatable
component.vue
<script>
import { VApiDatatable } from 'v-api-datatable'
export default {
components: { VApiDatatable },
}
</script>
main.js
import Vue from 'vue'
import VApiDatatable from 'v-api-datatable'
Vue.use(VApiDatatable, {
getData: async (resp) => {
return await resp.json();
},
getTotalItems: (resp, data) => {
return data.total;
},
getPerPage: (resp, data) => {
return data.per_page;
},
})
Name | Type | Args | Required | Description |
---|---|---|---|---|
getData | function |
response | -- | Unpacking data from response |
getTotalItems | function |
response | -- | Unpacking total items from response |
getPerPage | function |
response | -- | Unpacking per page items from response |
getItems | function |
response, data | -- | Get array items from response |
preSave | function |
method, args | -- | Pre save wrapper for v-crud-datatable |
const getData = (resp) => resp.data;
const getItems = (resp, data) => data.data;
const getTotalItems = (resp) => Number(resp.headers['x-pagination-total-count']);
const getPerPage = (resp) => Number(resp.headers['x-pagination-per-page']);
const preSave = (method, args) => method(args);
- method - request data from server. Return Promise
- headers - [{ text, value }, {text, value }]
- prettifyField - { type: Function, default: (item, key) => item[key] }: wrap data every item for prettify output. Attributes: item, key(value of current header)
- external-pagination - pagination via v-pagination
- get-data
- get-total-items
- get-per-page
- get-items
- pre-save
- includes all v-api-datatable props
- headers - Array<{ text: string, value: string, hiddenForTable?: boolean, hiddenForForm?: boolean, hiddenForEdit?: boolean, component: [object, string], listeners?: function, props?: [object] }>
- append-headers: { type: Array, default: () => [] } - headers after actions
- method-list: { type: Function, required: true }
- method-view: { type: Function, default: null }
- method-create: { type: Function, default: null }
- method-update: { type: Function, default: null }
- method-delete: { type: Function, default: null }
- serialize-data: { type: Function, default: (data: any) => data } - Before save data serialize
- serialize-instance-data: { type: Function, default: (data: any) => data } - After instance load data serialize
- dialog-edit-props: { type: Object, default: () => ({}) }
- dialog-delete-props: { type: Object, default: () => ({}) }
- deletion-text-value: { type: String, default: 'name' }
- includes all v-data-table slots
- search-fields: { searchKeys: any, runSearch: function }
- expand-search-fields: { searchKeys: any }
- search-actions: { searchKeys: any }
- item.(name): { item: any, index: number }
- header.(name): { header: any }
- row: { item: any }
- loading
- no-data
- no-results
- includes all v-api-datatable props
- item.actions.extra: { item: any }
- update(items)
- item:edit
- item:deleted
- item:updated
- item:created
- Add i18n
Welcome to contribute!
MIT © Komarov Roman