GithubHelp home page GithubHelp logo

coderdiaz / vue-datasource Goto Github PK

View Code? Open in Web Editor NEW
417.0 22.0 93.0 2.5 MB

A vue.js component to create dynamic tables

License: MIT License

HTML 0.95% Vue 36.51% JavaScript 62.54%
vue-datasource laravel pagination dynamic-tables vue vuejs vue2 table

vue-datasource's Introduction

[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

vue-datasource's People

Contributors

coderdiaz avatar codw99 avatar ismaaa avatar itsuwaribito avatar kingmario avatar matthewmarion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-datasource's Issues

Cannot use sort, filter, and limit

I'm using vue-cli simple webpack, and change the babel-preset of this module from stage 2 to stage 3.
The data display works fine but none of the sort, filter and limit function work. The limit only adds pages but the data display doesn't change.

Before using this, I ran the command
npm install babel-plugin-syntax-jsx babel-plugin-transform-vue-jsx babel-helper-vue-jsx-merge-props babel-preset-env

Please kindly help, thanks

data source support

Please include support for data source to be a data property instead of url.. eg. a client table. gracias

Access a button event method

This using vue-datasource and in this part when I already select a row, for example I want to call the delete method, but in the console it tells me this "this.deleteProducts() is not a function"

{
                        text: 'Delete',
                        icon: 'glyphicon glyphicon-trash',
                        class: 'btn-danger',
                        show (selectedRow) {
                            return true
                        },
                        event(e, row) {
                            console.warn('Are you clicked me?', e);
                            if(row == null) {
                                console.info('Ups.. data not found :(')
                            } else {
                                console.info('Yeeei, I found this :)', JSON.stringify(row));
this.deleteProducts(); <--------------------------------------
                            }
                        }
                    }

and it does not work. What is the correct way to call the method?

methods: {
deleteProduct: function(id){
                var url = 'products/'+id;
                axios.delete(url, {
                    id: this.id
                }).then(response => {
                    this.getProducts();
                    this.clear();
                    toastr.success('Se Elimino correctamente');
                }).catch(error => {
                    this.errors = error.response.data;
                });
            },
}

Unable to run tests

Unit tests fail on
cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run

Error is
Error: Cannot find module "@/components/Hello" at webpack:///test/unit/specs/Hello.spec.js:2:0 <- index.js:14309

Add sort event

Add sort event to configuration column with sort: true and order: [DESC, ASC]

Multiple select

It is not possible to select multiple lines by clicking on them, that would be really great !

Improve features

  • Update readme.
  • Change source prop url to array.
  • Remove loader.
  • Added support to add render jsx on column render.

Remove loader or configurable

The loader should be configurable and not forced to use it, although at this time, it would be preferable for the user to configure it on their own, so it could be removed.

Reference to #36

New logo design

Create a new logo design using the branding guidelines of vue.js.
Publish your idea here and vote

Dependency Error

I have a problem compiling the component, the following message appears:

These dependencies were not found:

`

  • @/components/SvgIcon in ./node_modules/babel-loader/lib?{"cacheDirectory":true,"presets":[["env",{"modules":false,"targets":{"browsers":["> 2%"],"uglify":true}}]],"plugins":["transform-object-rest-spread"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./node_modules/vue-datasource/src/components/ServerDatasource.vue
  • @/utils/DatasourceUtils in ./node_modules/babel-loader/lib?{"cacheDirectory":true,"presets":[["env",{"modules":false,"targets":{"browsers":["> 2%"],"uglify":true}}]],"plugins":["transform-object-rest-spread"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./node_modules/vue-datasource/src/components/ServerDatasource.vue
  • @/utils/EventBus in ./node_modules/babel-loader/lib?{"cacheDirectory":true,"presets":[["env",{"modules":false,"targets":{"browsers":["> 2%"],"uglify":true}}]],"plugins":["transform-object-rest-spread"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./node_modules/vue-datasource/src/components/ServerDatasource.vue
    `

The selected row is always active

The selected row remains active even when the information has already been changed and modified, so if the row exists in the new information it is selected again.

Arrays cannot be render value

For example:
columns: [ { name: 'status, key: 'status', filter: false, render(value) { // Render callback return # ${value}; } },
It works. Return '# + value of status'

But if you use 'meta.status' as the key, the render function won't do any compute, like this:
columns: [ { name: 'status, key: 'meta.status', filter: false, render(value) { // Render callback return # ${value}; } },
Nothing happend but only return the value of 'meta.status'.

Pagination limits cant set dynamically

Pagination limits set statically inside the component, could you make it as a prop to set dynamically by user in next version?

Default: limits: [1, 5, 10, 15, 20]

What I want to : limits: [10, 25, 50, 100]

Thank You

Enhancement request: Laravelish paginate

Hey, once again.

I would suggest to create adapter/transformer so we could pass some property and tell that this is definitely Laravel pagination, and it would parse laravel's paginate response.

Best wishes!

Update docs

Update a readme with new changes before upload a new version to npm

Show images in the table

Hello again, I'm trying to show an image in one of the columns without success, I'm doing it this way:

{
                        name: 'Photo',
                        key: 'photo',
                        render(value) {
                            return `<img src="/storage/uploads/userProduct/18-02-20-10-33-35_photo.png" />`;
                        }
                    },

And try also as the documentation shows but it does not work either:

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

Would you be so kind to help me show the images on the table, how should I do it?

Regards,

got dependencies error

when i run npm run dev. I use webpack.
These dependencies were not found:

  • @/assets/icon-sort-asc.svg in ./node_modules/vue-datasource/node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./node_modules/vue-datasource/src/components/ServerDatasource.vue

Create a Demo

Create a demo with multiple examples for vue-datasource using the docsfolder

Module parse failed: Unexpected token (11:6)

Compile failed

ERROR in ./node_modules/vue-datasource/src/components/ServerDatasource.vue?vue&type=script&lang=js& (./node_modules/vue-loader/lib??vue-loader-options!./node_modules/vue-datasource/src/components/ServerDatasource.vue?vue&type=script&lang=js&) 11:6 Module parse failed: Unexpected token (11:6)
You may need an appropriate loader to handle this file type. render (h) { return ( <div class="vue-server-datasource"> <div class="panel panel-default"> <div class="panel-heading">
@ ./node_modules/vue-datasource/src/components/ServerDatasource.vue?vue&type=script&lang=js& 1:0-121 1:137-140 1:142-260 1:142-260 @ ./node_modules/vue-datasource/src/components/ServerDatasource.vue @ ./node_modules/vue-datasource/src/index.js @ ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/components/backend/product/Index.vue?vue&type=script&lang=js& @ ./resources/js/components/backend/product/Index.vue?vue&type=script&lang=js& @ ./resources/js/components/backend/product/Index.vue @ ./resources/js/app.js @ multi ./resources/js/app.js

Project package versions :
`
"vue": "^2.6.7",
"vue-template-compiler": "^2.6.7",
"laravel-mix": "^4.0.7",

`

Pagination

Change the component for pagination to only set total items included on source, the paginator should be build only with this prop.

Enhancement... Sort

Felicitaciones por la libreria muy buena pero creo que le falta un feature de sorting ASC, DESC , etc

Enable Custom filtering

There may be occasions when you wish to search data presented to the end user in your own manner, common examples are number range search (in between two numbers) and date range search.

vuejs filter

Hi, how can i use for exemple vuejs filter "frenchDateFormat" on column render?
thank you

translation , column sorting and on type search

Hello, i've added portuguese translation by myself, but if you could add it by default would be awesome, also, i'm not sure yet if there is already, but sorting columns (if there isnt already) like this

https://jbaysolutions.github.io/vue-bootstrap-table/examples/01-basic.html

and the thing I would really appreciate if you could do is search on the type, like this thing (above example have on type filtering as well)

https://www.w3schools.com/howto/howto_js_filter_table.asp

Thanks in advance

How to render html?

We can not determine the type of column and unable to render as HTML.

Sample:

columns: [ { name: 'Id', key: 'id', render(value) { return '< input type="checkbox" name="ids[]" value="${value}" >'; } },

Is there a solution for this?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.