1.3.2 • Published 5 years ago

@pderas/vue2-table v1.3.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Vue Table

A simple vue component to render dynamic tables with sortable headers.

Initialize

Vue table is built as a vue plugin. It can be initialized just as the Vue documentation states.

import VueTable from '@pderas/vue2-table';

Vue.use(VueTable);

Usage

There are a few steps required before a vue table can be initialized.

1. Headers

Headers need to be defined before a table can be created. There are multiple options available for a header including it's label and if its sortable or not. A headers array that can be passed to vue table could look like this.

[{
    label: 'Status',
    sortBy: 'status'
    },
    {
        label: 'Client Name',
        sortBy: 'client_name'
    },
    {
        label: 'Service Date',
        sortBy: 'service_date'
    },
    {
        label: '',
        sortBy: '',
        disabled: true
}]

*Note: Notice the last header not having any labels. This column would be used for buttons on the row which is why the sorting is disabled.

Header Options

OptionDescriptionRequired
disabledBoolean that defines if a header can be clicked or notNo
labelThe title of the headerYes
sortByThe column name for the backend dataYes
widthA defined width for the header in px.No

2. Table

A vue table passes the information recieved from the url back into the view component so that it can be used in the row. A sample vue table could look like this.

<vue-table url="/clients/search" :headers="headers" :methods="methods">
    <template slot="row" slot-scope="{ row }">
        <tr>
            <td>{{ row.status }}</td>
            <td @click="row.methods.goTo('/clients')">
                {{ row.name }}
            </td>
            <td>{{ row.service_date }}</td>
            <td>Status</td>
        </tr>
    </template>
</vue-table>

If you want to run any functions with a row action you can pass them into the vue table using the methods prop. All methods are then accessible in the row using the row.methods object.

*Note: It is very important to define the scope of the template so that the data can be passed from the parent component into the children being defined for the rows.

Table Options

PropDescriptionRequired
headersAn array to populate the table headersYes
urlThe url to retrieve data from.No
dataAn array to define the table data if a url is not provided.No
hasSearchDisplay the search bar.No
methodsAn object containing any functions to run within a row of the table.No
paginateThe number of items to paginate the table to.No
searchParamsAn object of key/value pairs to add to the search.No
showEmptyPad paginated data with blank rows.No
beforeUpdateFunction to be called before updating the table.No
afterUpdateFunction to be called after updating the table.No
vuexSetThe name of the commit function to run for vuex integration.No
vuexGetThe name of the getter function to run for vuex integration.No

Search Bar Options

There are options to change the functionality of the search bar. These can be changed through the global options given when the plugin is activated.

import VueTable from '@pderas/vue2-table';

Vue.use(VueTable, {
    expandible: false,
    iconClasses: fa fa-search
});
OptionDescriptionValues
expandibleDetermines if the search expands on focus.true/false
iconClassesThe classes to generate the icon for the search barString
iconSideDetermines what side the icon shows on.left/right
searchWhenDetermines when a search is runonDelay/onEnter
timeoutDelayHow long to wait before running a new search. (Only applies when searchWhen set to 'onDelay')Number

Ajax Parameters

If a url is provided an ajax call is triggered every time a column is sorted or a search is run. The following parameters will be sent to the url provided.

ParameterDescription
orderThe order to sort the data by. Either 'asc' or 'desc'.
paginateThe amount of rows to paginate by.
selectedColThe sortBy value of the current column selected for sorting.
termThe current search term.

3. Customization

Slots are used to provide additional items to the table while still keeping styles coherent.

SlotDescription
rowDefines what a table row should look like.
actionsAdd actions buttons inline with the search bar

License

This project is covered under the MIT License. Feel free to use it wherever you like.

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago