Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 10, 2021. It is now read-only.

A vue.js component to create dynamic tables

License

NotificationsYou must be signed in to change notification settings

coderdiaz/vue-datasource

Repository files navigation

[WIP] Vue Datasource go back renew. Coming soon V3.

Vue Datasource

A Vue.js component to create dynamic tables. Compatible with Vue 2.x and Laravel.


Demo

Donate

Buy me a coffeeBuy me a coffee

Install/Usage

For use this package is necessary installbabel-plugin-transform-vue-jsx dependency.

$ npm install vue-datasource
<divid="#app"><server-datasource:source="items":total="total_of_items":columns="columns":actions="actions"></server-datasource></div>
import{ServerDatasource}from'vue-datasource'newVue({el:'#app',components:{        ServerDatasource},data(){return{items:[...],total:100,columns:[...],actions:[...]}}});

Documentation

Available Props

PropTypeDefaultDescription
sourceArrayItems to show in table
totalNumberTotal of items
translationObject[Object]Defines the table labels language (structure)
limitsArray[1,5,10,15,20]Defines the limits to display
columnsArrayColumns to display
actionsArrayAction buttons (structure)

Available Events

EventDescription
changeHandle show limit changed. Gets object with new show limit and current page{perpage: 10, page: 2}
searchingHandles search input. Gets string as parameter
column-sortOnly iforder is defined in column array. Return the current column sorted with metadata (Sort Column)

Columns

Each column object needsname andkey attributes.

{    ...,columns:[{name:'Name',// Table column name to displaykey:'name',// Key name from row object}]}

Laravel users 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 role we would need to define in our columns array:

{    ...,columns:[{name:'Role',key:'role.name'}]}

Sort column

[New] You only need aorder property in column defined for use this feature.

{    ...,columns:[{name:'Name',key:'name',order:true}]}

This feature emit a eventcolumn-sort with this data object

{sort:{key:'name',order:false},type:'DESC'}

Render column

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}`;}}]}

[New] Now you can use JSX for render other templates and too use the row data.

{    ...,columns:[{name:'Name',key:'key',render(value,row){return<strong>{value}</strong>}}]}

Translation Structure

{limit:'Limit',search:'Search',placeholder_search:'Type to search..',records_not_found:'No records found',pagination:{show:'Showing',to:'to',of:'of',entries:'entries'}}

Action Event Sctructure

{    ...,actions:[{text:'Click me',// Button labelicon:'glyphicon glyphicon-check',// Button iconclass:'btn-primary',// Button class (background color)show(selectedRow){// Event to define a condition to display the button with the selected rowreturntrue},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}}]}

Development

# install dependenciesnpm install# serve with hot reload at localhost:8080npm run dev# build for production with minificationnpm run build# build for production and view the bundle analyzer reportnpm run build --report# run unit testsnpm run unit# run e2e testsnpm run e2e# run all testsnpmtest

For detailed explanation on how things work, checkout theguide anddocs for vue-loader.

Implementation examples

Contributions

All contributions are welcome send your PR and Issues.

License

This is a open-source software licensed under theMIT license

Crafted by Javier Diaz. Translation byitsuwaribito

About

A vue.js component to create dynamic tables

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp