- Notifications
You must be signed in to change notification settings - Fork91
A vue.js component to create dynamic tables
License
coderdiaz/vue-datasource
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Vue.js server side component to create dynamic tables. Compatible with Vue 2.x and Laravel.
Live:https://young-falls-97690.herokuapp.com/
$ npm install vue-datasource
<divid="#app"><datasourcelanguage="en":table-data="information.data":columns="columns":pagination="information.pagination":actions="actions"v-on:change="changePage"v-on:searching="onSearch"></datasource></div>
importDatasourcefrom'vue-datasource'newVue({el:'#app',components:{ Datasource},data(){return{information:{pagination:{...},data:[...]},columns:[...],actions:[...]}},methods:{changePage(values){...},onSearch(searchQuery){...}}});
Prop | Type | Default | Description |
---|---|---|---|
table-data | Array | Table information | |
language | String | es | Defines the table labels language |
columns | Array | Columns to display | |
pagination | Object | Pagination information about the table data ([structure] (#pagination-structure)) | |
actions | Array | Action buttons ([structure] (#action-event-sctructure)) |
Event | Description |
---|---|
change | Handle show limit changed. Gets object with new show limit and current page{perpage: 10, page: 2} |
searching | Handles search input. Gets string as parameter |
Language | Abbr |
---|---|
Spanish | es |
English | en |
French | fr |
Chinese (Simplified) | zh-CN |
Each column object needs aname
andkey
attributes.
{ ...,columns:[{name:'Name',// Table column name to displaykey:'name',// Key name from row object}]}
For Laravel users, you can access relationships through thekey
attribute. Lets say we have the following object in our users array.
[ ...,{name:'Foo',last_name:'Bar'role_id:1,role:{name:'admin'}}]
To get the user's role we would need to define in our columns array:
{ ...,columns:[{name:'Role',key:'role.name'}]}
This callback will modify the data for various operations. Such as applying a specific format or an arithmetic operation to the column value and return it.
{ ...,columns:[{name:'Name',key:'name',render(value){// Render callbackreturn`Enginner${value}`;}}]}
{ ...,pagination:{total:25,// Number of total rows (default 0)per_page:15,// Number of rows to show (default 15)current_page:1,// Actual pagelast_page:2,// Last pagefrom:1,// Beginning of visible rowsto:15// End of visible rows}}
{ ...,actions:[{text:'Click me',// Button labelicon:'glyphicon glyphicon-check',// Button iconclass:'btn-primary',// Button class (background color)event(e,row){// Event handler callback. Gets event instace and selected rowconsole.log('Click row: ',row);// If no row is selected, row will be NULL}}]}
- Using Laravel 5.3 and pagination:laravel-datasource-example.
All contributions are welcome send your PR and Issues.
Vue Datasource is open-sourced software licensed under theMIT license
Created by Javier Diaz. Translation enhancement by [itsuwaribito] (https://github.com/itsuwaribito)
About
A vue.js component to create dynamic tables
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors6
Uh oh!
There was an error while loading.Please reload this page.