• This repository has been archived on 10/Jun/2021
  • Stars
    star
    422
  • Rank 102,753 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A vue.js component to create dynamic tables

[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 install babel-plugin-transform-vue-jsx dependency.

$ npm install vue-datasource
<div id="#app">
    <server-datasource
        :source="items"
        :total="total_of_items"
        :columns="columns"
        :actions="actions"></server-datasource>
</div>
import { ServerDatasource } from 'vue-datasource'

new Vue({
    el: '#app',
    components: {
        ServerDatasource
    },
    data() {
        return {
            items: [...],
            total: 100,
            columns: [...],
            actions: [...]
        }
    }
});

Documentation

Available Props

Prop Type Default Description
source Array Items to show in table
total Number Total of items
translation Object [Object] Defines the table labels language (structure)
limits Array [1,5,10,15,20] Defines the limits to display
columns Array Columns to display
actions Array Action buttons (structure)

Available Events

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
column-sort Only if order is defined in column array. Return the current column sorted with metadata (Sort Column)

Columns

Each column object needs name and key attributes.

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

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

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

Sort column

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

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

This feature emit a event column-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 callback
                return `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 label
            icon: 'glyphicon glyphicon-check', // Button icon
            class: 'btn-primary', // Button class (background color)
            show(selectedRow) { // Event to define a condition to display the button with the selected row
                return true
            },
            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
            }
        }
    ]
}

Development

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

# run unit tests
npm run unit

# run e2e tests
npm run e2e

# run all tests
npm test

For detailed explanation on how things work, checkout the guide and docs for vue-loader.

Implementation examples

Contributions

All contributions are welcome send your PR and Issues.

License

This is a open-source software licensed under the MIT license

Crafted by Javier Diaz. Translation by itsuwaribito

More Repositories

1

vue-tiny-pagination

A Vue component for create a tiny pagination with Flexbox
JavaScript
20
star
2

react-card-brand

A zero-dependency React Hook to show the brand from a card type.
TypeScript
10
star
3

airbnb-clone-api

API using Express, Mongoose, Node and Firebase Auth based on Airbnb.
JavaScript
10
star
4

website

My personal website built in with Next.js, MDX and TailwindCSS 🔥. Hosted in ▲ Vercel.
TypeScript
9
star
5

yelpi

A website built on NextJS to search business from Yelp via GraphQL based on terms and location.
TypeScript
8
star
6

codigofacilito-examples

JavaScript
7
star
7

who-use-vuejs-in-mexico

Who use Vue.js in Mexico?
6
star
8

vue-transformicons

Transformicons for Vue
JavaScript
5
star
9

scoreboard

Scoreboard based on Treehouse's Course builded with Vue
Vue
5
star
10

nestjs-fastify-graphql

A nest.js template with Typescript, GraphQL and Fastify
TypeScript
3
star
11

coderdiaz

3
star
12

node-airbnb-clone

A simple node application based in airbnb.com
JavaScript
3
star
13

forum-web

A web application crafted with Node, Express, Pug, Mongo
JavaScript
2
star
14

fundamentos-de-react

Clases y código de las clases de fundamentos de react.js
JavaScript
2
star
15

gravity-vscode-theme

A VS Code theme for a dawn lovers 🌅 with accesible colors.
2
star
16

yell-vscode-theme

A VS Code theme for dark lovers with accesible colors. ✨
2
star
17

vue-cli-pokedex

Pokedex App created with Vue CLI 3
JavaScript
2
star
18

scaffolding

JavaScript
1
star
19

the-new-web

Coming to publish a website focused to be a Product Engineer by default
1
star
20

vue-course

1
star
21

demo-express

JavaScript
1
star
22

image-component

JavaScript
1
star
23

template-next-ts

A NextJS template with support for use typescript and tailwindcss
TypeScript
1
star
24

webpage-with-react

A web example using React
JavaScript
1
star
25

first-batch-react

JavaScript
1
star
26

tuffybrain-vscode-theme

A color theme inpired on Jetbrains Theme with accesible colors
1
star
27

error-handling

TypeScript
1
star
28

v4

My personal website built with Next.js and TailwindCSS with Dark Mode support.
TypeScript
1
star
29

landing-page-sample-webgl

JavaScript
1
star
30

vue-glidejs-wrapper-example

An example for how to create a Vue wrapper for use external libraries
Vue
1
star
31

rating-movies-api

API for publish movies and reviews
JavaScript
1
star
32

nest-api

A demo application using NestJS
TypeScript
1
star
33

dom-events

Examples using DOM manipulation with JavaScript by Codigo Facilito Frontend Bootcamp
HTML
1
star
34

taller-dom

Created with StackBlitz ⚡️
JavaScript
1
star
35

vue-airbnb-spa

Airbnb clone with Vue SPA
JavaScript
1
star
36

next-mdx-template

TypeScript
1
star
37

vue-professional-boilerplate

Arquitecturas con Vue - Diseño y vistas
JavaScript
1
star
38

onboarding-example

JavaScript
1
star
39

nest-api-key

1
star
40

node-dogsteps

Node application
JavaScript
1
star
41

template-vanilla-vite

CSS
1
star
42

dw-javascript

JavaScript
1
star
43

v3

Personal website by Javier Diaz
CSS
1
star
44

strapi-demo

JavaScript
1
star
45

vue-glider

A Vue wrapper for Glider.js
Vue
1
star
46

tablo

1
star
47

codigofacilito-nextjs

JavaScript
1
star
48

strapi-rich-text

A Strapi v4 custom fields to add richness and emphasis to short and long texts.
JavaScript
1
star
49

react-frontend-test

React Application - Testing navigation with Autocomplete Dropdown
CSS
1
star