2.0.7 • Published 6 years ago

vue-datasource v2.0.7

Weekly downloads
121
License
MIT
Repository
github
Last release
6 years ago

Demo

forthebadge forthebadge

'Screenshot'

Live: https://young-falls-97690.herokuapp.com/

Install/Usage

$ npm install vue-datasource
<div id="#app">
    <datasource
        language="en"
        :table-data="information.data"
        :columns="columns"
        :pagination="information.pagination"
        :actions="actions"
        v-on:change="changePage"
        v-on:searching="onSearch"></datasource>
</div>
import Datasource from 'vue-datasource'

new Vue({
    el: '#app',
    components: {
        Datasource
    },
    data() {
        return {
            information: {
                pagination: {...},
                data: [...]
            },
            columns: [...],
            actions: [...]
        }
    },
    methods: {
        changePage(values) {...},
        onSearch(searchQuery) {...}
    }
});

Available Props

PropTypeDefaultDescription
table-dataArrayTable information
languageStringesDefines the table labels language
columnsArrayColumns to display
paginationObjectPagination information about the table data (structure)
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

Available Languages

LanguageAbbr
Spanishes
Englishen
Frenchfr
Chinese (Simplified)zh-CN
Catalanca

Columns

Each column object needs a name and key attributes.

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

For Laravel users, you can access relationships through the key 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'
        }
    ]
}

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 callback
                return `Enginner ${value}`;
            }
        }
    ]
}

Pagination Structure

{
    ...,
    pagination: {
        total: 25, // Number of total rows (default 0)
        per_page: 15, // Number of rows to show (default 15)
        current_page: 1, // Actual page
        last_page: 2, // Last page
        from: 1, // Beginning of visible rows
        to: 15 // End of visible rows
    }
}

Action Event Sctructure

{
    ...,
    actions: [
        {
            text: 'Click me', // Button label
            icon: 'glyphicon glyphicon-check', // Button icon
            class: 'btn-primary', // Button class (background color)
            event(e, row) { // Event handler callback. Gets event instace and selected row
                console.log('Click row: ', row); // If no row is selected, row will be NULL
            }
        }
    ]
}

Implementation examples

Contributions

All contributions are welcome send your PR and Issues.

License

Vue Datasource is open-sourced software licensed under the MIT license

Created by Javier Diaz. Translation enhancement by itsuwaribito
1.0.12

6 years ago

2.0.7

6 years ago

2.0.6

7 years ago

2.0.5

7 years ago

1.0.10

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago