GithubHelp home page GithubHelp logo

uwla / vue-data-table Goto Github PK

View Code? Open in Web Editor NEW
127.0 3.0 22.0 4.05 MB

Vue plugin that adds advanced features to an HTML table.

Home Page: https://uwla.github.io/vue-data-table/demo

Vue 13.46% SCSS 8.57% TypeScript 76.93% HTML 0.37% CSS 0.67%
data-table vue vue2 vue3

vue-data-table's Introduction

VUE DATA TABLE

VueDataTable is a Vue plugin that adds advanced features to an HTML table.

It was inspired by DataTable jQuery Plugin, but was written from scratch in Vue.

FEATURES

  • Pagination
  • Search filter
  • Single column sorting
  • Multiple column sorting
  • Customize every visible text
  • Support for multiple languages
  • Export data (JSON, CVS, TXT or XLS)
  • Action buttons (view, edit, delete)
  • Editable cells (edit cell values)
  • Custom Vue components to render cells
  • Custom Footer to display data summary
  • Support for Vue3 and Vue2

DEMO

The best way to see if a package suits your needs is by viewing and testing its functionalities via a demo app.

There is also this CodeSandbox Playground in which you can edit the source code with live preview.

GETTING STARTED

Installation

npm install @uwlajs/vue-data-table

Make sure to install version 2.0.0 or above for Vue3.

Versions prior to 2.0.0 are for Vue2. Checkout the vue2 branch for its documentation.

Set up

import VueDataTable from "@uwlajs/vue-data-table";
Vue.component("vue-data-table", VueDataTable);

Don"t forget to add the style sheets

import "@uwlajs/vue-data-table/dist/VueDataTable.css";

Usage

<template>
    <div>
        <data-table v-bind="bindings"/>
    </div>
</template>
<script>
export default {
    computed: {
        bindings() {
            return {
                columns: [/*the columns*/]
                data: [/*the data*/]
                /* other props...*/
            }
        }
    },
}
</script>

Note Notice that v-bind will take all key-value pairs in the object (in this case, the bindings), and pass them as props to the VueDataTable. So, this is a shortcut to pass multiple props at once.

CONFIGURATION

Only data e columns are required. Other props are optional.

prop type default description
data Array - Array of objects with the data to be displayed on the table
columns Array - Array of objects to specify how to render each column. Optional if columnKeys is set
columnKeys Array - Array of strings matching the object keys in data. Discarded if columns is set
lang String en The default language
perPageSizes Array [10, 25, 50, 100, '*'] The options for the number of rows being displayed per page. The string '*' shows all.
defaultPerPage Number 10 The default number of entries. If unset, then it will be the first value of perPageSizes
isLoading Bool false Whether table data is loading. Table rows are shown only if this value is set to false
loadingComponent String, Object - VueJS component to be shown if isLoading is set to true
showPerPage Bool true Whether to show the PerPage component
showEntriesInfo Bool true Whether to show the EntriesInfo component
showSearchFilter Bool true Whether to show the SearchFilter component
showPagination Bool true Whether to show the Pagination component
showDownloadButton Bool true Whether to show the button to download the table's data
tableClass String table table-striped table-hover The table's HTML class attribute
sortingMode String multiple Whether to sort a single column or multiple columns at once
sortingIndexComponent String, Object VdtSortingIndex VueJS component for the sorting index on sortable columns
sortingIconComponent String, Object VdtSortingIcon VueJS component for the sorting icon on sortable columns
footerComponent String, Object null VueJS component for custom table footer
allowedExports Array ["csv", "json", "txt"] Formats the user can export the data to. Allowed values: csv, json, txt, xlsx

Columns

key type default description
key String - The object field to be displayed in a table cell
title String titleCase(key) The title displayed in the header
searchable Bool true Whether to allow searching rows by this column field
sortable Bool true Whether to allow sorting the data by this column field
editable Bool true Whether the column is editable by the user
type String string Data type of key. Allowed values: string, number
compareFunction Function - Custom function provided by the user to sort the column
searchFunction Function - Custom function provided by the user to search the column
index Number 1000 Lower values shift the column to the left of the table
component String, Object - Custom Vue component to render inside table cell
componentProps Object - Props to pass to the custom component

If columns is not defined, then columnKeys must be defined and it will be mapped to a columns array with the default parameters. Example:

// we can define the columns
config = {
    data: users,
    columns: [
        {
            key: "name",
        },
        {
            key: "email",
            title: "Email Address",
            sortable: false,
        },
        {
            key: "phone",
            sortable: false,
            searchable: false,
            index: 1, // smaller indexes means the column is shift to the left
        },
        {
            key: "permissions",

            /* custom function sort users by which user has more permissions */
            compareFunction: function(a, b) {
                // permissions is an array
                return a.permissions.length - b.permissions.length;
            },

            /* custom function to allow searching the permission array */
            searchFunction: function(search, data) {
                return data.permissions.some(permission => permission.includes(search))
            },

            searchable: true,

            /* custom component to display the permissions */
            component: UserPermissionList,
        }
    ]
}

// or use columnKeys shortcut
config = {
    data: user,
    columnKeys: ["name", "email", "registered_at", "last_access_at"]
},

// which will take the default column and map the array into this
[
    {
        key: "name",
        title: "Name",
        sortable: true,
        searchable: true,
        index: 1000
    },
    {
        key: "email",
        title: "Email",
        sortable: true,
        searchable: true,
        index: 1000
    },
    {
        key: "registered_at",
        title: "Registered At",
        sortable: true,
        searchable: true,
        index: 1000
    },
    {
        key: "last_access_at",
        title: "Last Access At",
        sortable: true,
        searchable: true,
        index: 1000
    },
]

Custom Cell Component

Custom cell components must have a data property to receive the data of the current row for the component to display it.

In the previous code snippet, we used our custom component UserPermissionList. Below is a sample of that custom component.

<template>
    <div>
        List of permissions for the user {{ data.name }} :
        <ul>
            <li v-for="(permission, i) in data.permissions" :key="i">
                {{ permission }}
            </li>
        </ul>
    </div>
</template>
<script>
export default {
    name: "UserPermissionList",
    props: {
        data: {
            type: Object,
            required: true
        }
    }
}
</script>

To handle events triggered by a custom component (such as clicking a button in a component), the component should emit an event called userEvent and pass an arbitrary payload to it. The event will be propagated upwards by VueDataTable, which will also emit an event called userEvent whose payload is the same as the one emitted by the custom component. For example:

<template>
    <input type="checkbox" class="form-control" :checked="value" @change='toggleChecked' />
</template>
<script>
export {
    name: 'CheckboxCell',
    data() {
        return {
            value: false,
        }
    },
    methods: {
        toggleChecked() {
            const payload = {
                id: this.data.id,
                checked: this.value,
            }
            this.$emit('userEvent', payload)
        }
    },
    props: {
        data: Object,
    }
}
</script>

When the users clicks the checkbox, it will emit an userEvent event, which can be accessed from the VueDataTable. Here is an continuation of the previous example.

<template>
    <div class="dashboard">
        <h1>DASHBOARD</h1>
        <button class="btn btn-danger">
            DELETE SELECTED ROWS
        </button>
        <vue-data-table
            :data="data"
            :columns="columns"
            @userEvent="handleEvent" />
    </div>
</template>
<script>
export default {
    data() {
        return {
            data: [/**/],
            columns: [/**/],
            selectedRows: [],
        }
    },
    methods: {
        handleEvent(payload) {
            const { checked, id } = payload
            if (checked === true) {
                if (! this.selectedRows.includes(id))
                    this.selectedRows.push(id)
            } else {
                this.selectedRows = this.selectedRows.filter(rowId => rowId !== id)
            }
        },
        deleteRows() {
            this.data = this.data.filter(row => ! this.selectedRows.includes(row.id))
            this.selectedRows = []
        }
    }
}
</script>

In the code snippet above, when the user checks the checkbox rendered by the custom component CheckboxCell, it will emit an event that is handled by the method handleEvent. This method will add/remove the id of the row to/from the selectedRows array. When the user clicks the "dangerous delete button", it will deleted the selected rows from the table (on the client side only).

Action Buttons

VueDataTable provides a component called VdtActionButtons, which can be used to display buttons for common CRUD action such as viewing, editing, deleting.

Here is an example with all buttons (view, edit, delete) in one column:

<template>
    <main>
        <h1>DASHBOARD</h1>
        <vue-data-table v-bind="params" @userEvent="handleUserEvent"/>
    </main>
</template>
<script>
import { VdtActionButtons } from '@uwlajs/vue-data-table'
export default {
    data() {
        return {
            params: {
                data: users,
                columns: [
                    { key: 'name' },
                    { key: 'job' },
                    { component: VdtActionButtons, title: "actions" },
                ],
            },
        }
    },
    methods: {
        handleUserEvent(payload) {
            console.log(payload.action, payload.data.name)
        }
    }
}
</script>

Another example, this time one button per column:

<template>
    <main>
        <h1>DASHBOARD</h1>
        <vue-data-table v-bind="params" @userEvent="handleUserEvent"/>
    </main>
</template>
<script>
import { VdtActionButtons } from '@uwlajs/vue-data-table'
export default {
    data() {
        return {
            params: {
                data: users,
                columns: [
                    { key: 'name' },
                    { key: 'job' },
                    {
                        title: "view"
                        component: VdtActionButtons,
                        componentProps: { actions: ["view"] },
                    },
                    {
                        title: "edit"
                        component: VdtActionButtons,
                        componentProps: { actions: ["edit"] },
                    },
                    {
                        title: "delete"
                        component: VdtActionButtons,
                        componentProps: { actions: ["delete"] },
                    },
                ],
            },
        }
    },
    methods: {
        handleUserEvent(payload) {
            console.log(payload.action, payload.data.name)
        }
    }
}
</script>

When an user click an action button, VueDataTable will emit an event whose payload is an object with two fields: action and data. The action is the name of the action (view, edit, delete) and data is the data of the row.

Check out the demo to see a real working example of using action buttons.

Editable cells

It is possible to make a column editable by settings editable to true in the column definition.

columns: {
    [ 'key': name, editable: true],
    [ 'key': email, editable: true],
    [ 'key': phone, editable: true],
    // ...
}

This will make VueDataTable display an edit button on the right side of the cell's text. When the user clicks the button, it will show an input, so the user can enter a new value for the cell. The user can cancel the editing or confirm. If the user confirms editing, VueDataTable will emit a userEvent whose payload looks like the following:

{
    action: 'updateCell',
    key: '<key String>',
    data: '<data Object>',
    value: '<value String>',
}

Where key is the key of the column (if user edits the name column, the key will be name), the data is the object of the row which was edit (an example: { id: 100, name: 'joe', email: '[email protected]' }), and value is the value inserted by the user (such as Joe Doe).

It is up to the developer to handle the event to update the row by, for example, sending an AJAX request to the API, then updating the data array on the client side. Here is an example of how to update the data array on the client side:

<template>
  <vue-data-table :data="data" :columns="columns" @userEvent="handleUserEvent"/>
</template>
<script>
export default {
    /* ... */

    methods: {
        handleUserEvent(payload) {
            if (payload.action === 'updateCell')
            {
                // send some ajax request
                // ...

                // then update the cell
                this.updateDataCell(payload.data, payload.key, payload.value)

            } else {
                // some other event
            }
        },
        updateDataCell(row, field, value) {
            let ind = this.data.findIndex(r => r.id === row.id)
            if (ind < 0) return
            let newRow = {... this.data[ind]}
            newRow[field] = value
            this.data.splice(ind, 1, newRow)
        },
    }
}
</script>

Text

Currently, VueDataTable has support for the following languages: English (en), Brazilian Portuguese (pt-br), and Spanish(es). The lang prop specifies in which language to display the text in our table.

If we want to add a custom text (maybe because there is no language support or because we want something else), we have to set it in the text prop.

The following table shows the texts we can customize and their default values for the English language.

key default
perPageText "Show :entries entries"
perPageAllText "ALL"
infoText "Showing :first to :last of :total entries"
infoAllText "Showing all entries"
infoFilteredText "Showing :first to :last of :filtered (filtered from :total entries)"
nextButtonText "Next"
previousButtonText "Previous"
paginationSearchText "Go to page"
paginationSearchButtonText "GO"
searchText "search:"
downloadText "export as:"
downloadButtonText "DOWNLOAD"
emptyTableText "No matching records found"

Note: Notice that the placeholders :first, :last, :total, and :filtered will be automatically replaced with the proper numbers.

Example code:

parameters() {
    return {
        data: [/**/],
        columns: [/**/],
        text: {
            PerPageText: "Number of users per page :entries",
            infoText: "Displaying :first to :last of :total users",
            emptyTableText: "No users found :(",
        }
    }
}

Adding Language

If your language is not yet supported, you can add a new language and use it in any VueDataTable instance as follow:

import { languageServiceProvider } from "@uwlajs/vue-data-table";

const loremIpsumLanguage = {
    perPageText: "lorem ipsum",
    nextButtonText: "labore ipsum",
    /* more ... */
};

languageServiceProvider.setLang("lorem", loremIpsumLanguage)

You can also change any default text for an existing language and that will reflect the changes globally. For example:

// the default text for the download button in the export component is "export as"
// we may want change that to "download as"
languageServiceProvider.setLangText("en", "downloadText", "download as:")

Layout

VueDataTable uses CSS's grid display to specify the position of its components (search filter, pagination, entries info, per page options, download button).

We can specify the position of the components by including our custom CSS/SCSS and overriding the defaults.

By default, this is how VueDataTable displays the components:

.data-table {
    display: grid;
    width: 100%;
    grid-template-columns: 25% 25% 25% 25%;
    &> div {
        margin-top: 1rem;
        max-width: 100%;
    }
    & > .data-table-search-filter, .data-table-pagination, .data-table-export-data {
        margin-left: auto
    }
    @media (min-width: 1401px) {
        grid-template-areas:
            "perPage search search search"
            "table table table table"
            "info pagination pagination download";
    }
    @media (min-width: 1051px) AND (max-width: 1400px) {
        grid-template-areas:
            "perPage search search search"
            "table table table table"
            "info pagination pagination pagination"
            ". . download download";
    }
    @media (min-width: 851px) AND (max-width: 1050px) {
        grid-template-areas:
            "perPage search search search"
            "table table table table"
            "pagination pagination pagination pagination"
            "info info download download";
    }
    @media (max-width: 800px) {
        & > .data-table-pagination {
            flex-wrap: wrap;
        }
    }
    @media (min-width: 651px) AND (max-width: 850px) {
        grid-template-areas:
            "perPage search search search"
            "table table table table"
            "pagination pagination pagination pagination"
            "info info info info"
            "download download download download";
    }
    @media (max-width: 650px) {
        grid-template-areas:
            "search search search search"
            "perPage perPage perPage perPage "
            "table table table table"
            "pagination pagination pagination pagination"
            "info info info info"
            "download download download download";
        & > .data-table-per-page {
            margin-left: auto
        }
    }
}

Feel free to copy the styles above, modify it, and then set the position of the components as you want.

Custom Components

Besides a custom component for each column, you provide custom components for the table's footer, the column's sorting icon (the icon displayed if the columns is sorted), and the column's sorting index (the index of the current column if it is being sorted and multi column sorting is enabled).

Footer

The property footerComponent sets the component to render the table's footer. The component can be either the component Object, or a String equals to the name of the registered component.

The footerComponent must be a <tfoot> HTML element and it must have the properties data, dataDisplayed, dataFiltered. If the component does not specify those properties in props, Vue will probably think they are some custom HTML attribute and their values will be show as HTML attributes, which is really messy.

The property data correspond to all data passed to VueDataTable. The dataDisplayed corresponds to all data that is currently visible on the table. The dataFiltered corresponds to all data that was filtered by a search query. These properties can be used to perform common operations such as calculating the sum of the values of the total rows of a certain column.

Suppose we have a table that of fruits. The data is an array of objects whose properties are name, price, and amount. We can provide a custom footer to show the total amount of fruits bought and the total price.

The footer component would be something like:

<template>
  <tfoot v-show="dataDisplayed.length > 0">
    <td>Total</td>
    <td></td>
    <td>{{ totalAmount }}</td>
    <td>{{ totalPrice }}</td>
  </tfoot>
</template>
<script>
export default {
  name: "TableFooter",
  computed: {
    totalPrice() {
      let s = 0;
      for (let f of this.dataDisplayed)
        s += f.price * f.amount;
      return s;
    },
    totalAmount() {
      let s = 0;
      for (let f of this.dataDisplayed)
        s += f.amount;
      return s;
    }
  },
  props: {
    data: Array,
    dataDisplayed: Array,
    dataFiltered: Array,
  }
}
</script>

And we pass this component as follow:

<template>
    <data-table v-bind="tableProps"/>
</template>
<script>
import TableFooter from './TableFooter.vue'

export default {
    /* ... some code */
    data() {
        return {
            tableProps: {
                columns: [ /* ... code */ ],
                data: [ /* ... more code */ ],
                footerComponent: TableFooter,
            }
        }
    }
}
</script>

Alternately, you can register the component and pass a string:

/* early on */
import TableFooter from './TableFooter.vue'
Vue.component("table-footer", TableFooter)

/* later on */
    footerComponent: "table-footer"

Sorting Icon

By default, VueDataTable will display arrows to indicate the sorting direction when sorting a column. The SortingIcon component is wrapped in a th element. The th element has a data-sorting attribute that may be asc or desc only. Based on this value, we display an arrow_up or an arrow_down icon using CSS rules.

<template>
    <span class="data-table-sorting-icon">&nbsp;</span>
</template>
<style lang="scss" scoped>
.data-table-sorting-icon {
    &::after {
        content: "\2193";
    }
    &::before {
        content: "\2191";
    }
    &::after, &::before {
        opacity: 0.5;
    }
    [data-sorting="asc"] &::before, [data-sorting="desc"] &::after {
        opacity: 1;
    }
}
</style>

Note: Some code was omitted to keep it clean.

If we want to add our custom icons for this, then we can register our component, like so:

import SortingIcon from "./path/to/SortIcon.vue";

export default {
    computed: {
        bindings() {
            return {
                SortingIconComponent: SortingIcon,
                data: [],
                /**/
            };
        }
    }
}

Sorting Index Icon

When sorting multiple columns, VueDataTable will display an icon with a index indicating which column has the priority in the sorting process.

<template>
    <span class="data-table-sort-index">
        {{ index }}
    </span>
</template>

If we want to add our own component for this, we can register it just like we did before.

import SortingIndex from "./path/to/SortingIndex.vue";

export default {
    computed: {
        bindings() {
            return {
                SortingIndexComponent: SortingIndex,
                data: [],
                /**/
            };
        }
    }
};

In our SortingIndex component, we must have a index property, which correspondent to the index of the column in the sorting process.

export default {
    name: "SortingIndex",
    props: {
        index: {
            type: Number,
            required: true
        }
    }
};

ROADMAP

  • Support for Vue3
  • Support for SSR
  • String notation for defining columns

LICENSE

MIT

CONTRIBUTING

Pull requests are very welcome.

vue-data-table's People

Contributors

dependabot[bot] avatar uwla 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

vue-data-table's Issues

How can i access data from nested object

i have respone like this

data:{
    user: {
        name: 'Jonh',
        email: '[email protected]', 
        phone: '+002011111111'.
    },
    role: {
        name: 'admin_role',
        permissions: [
            {
                id: 1,
                name: 'add user',
            },
            {
                id: 2,
                name: 'edit user',
            },
            {
                id: 3,
                name: 'delete user',
            }
        ],
    },
}

when am trying to access email from user is not working

columns: [
{
title: 'Email Address',
key: 'user.email',
},
]

Custom cell component with input not re-rendering on search filter

Hi @uwla

I am currently experiencing an issue where the value of input fields in custom cell components is not correctly re-rendering when filtering via search.

I've created a Codesandbox example to show what I mean.

Notice that when filtering via search, the values of the input fields in column 3 don't update or re-render. The first entry has a job of 'Recreational Therapist', but when filtering for 'Corine', it still has the value of 'Recreational Therapist'.

Is this an issue with VDT or am I doing something wrong here regarding Vue?

Thanks in advance!

Put <img> tag into data

Hi dude

I want show image in table but i CANT!
I tried to put into my Array to showing in Table, but after render that not show any image and just show text like this:
<img src="example.com/img.png">

for (let index = 0; response.body.data.courses.length > index; index++) {
let need = {
id: index + 1,
name: response.body.data.courses[index].name,
slug: response.body.data.courses[index].slug,
cover: "<img src='"+response.body.data.courses[index].cover+"' width='40' height='40'/>",
category: response.body.data.courses[index].category.name,
teacher: response.body.data.courses[index].teacher.name,
price: addCommas(response.body.data.courses[index].price) + ' TR'
};
arr.unshift(need);
}
how can i showing image in table ?

im so sry for my bad english

How to get a value if value is an object?

I an getting data from backend using laravel.

my question is.
in columns array i have set a key : category.
Category is nested object.
how to get category value. like name or anything.

i am tried 'category.name' but not working.

Thank You

Add custom prop to custom action component

Hello, AndreSouzaAbreu

Thank you for open-sourcing this elegant table.
Please I need your help.

My table version is 3.2.1 . How can I pass custom props into the table?

The component containing the table

 allTasksTable() {
        return {
          data: this.tasks,
          columns: [
            {
              key: 'id',
              title: 'Id',
              sortable: true,
              searchable: true,
              index: 0,
            },
            {
              key: 'name',
              title: 'Name',
              sortable: true,
              searchable: true,
              index: 0,
            },
            {
              key: 'actions',
              component: ActionButtons,
            },
          ],
        };
      },

The component in the actions column

<template>
  <div class="action-buttons">
    <button class="btn btn-outline-success" @click="handleAction('view')">
      <i class="icon-feather-eye"></i>
    </button>
    <button class="btn btn-outline-primary" @click="handleAction('edit')">
      <i class="icon-feather-edit"></i>
    </button>
    <button class="btn btn-outline-dark" @click="handleAction('delete')">
      <i class="icon-feather-trash"></i>
    </button>
  </div>
</template>

<script>
  /* eslint-disable no-console */
  export default {
    name: 'ActionButtons',
    methods: {
      handleAction(actionName) {
        /* when the user clicks a button, that will trigger a mutation on our Vuex store
            The mutation may show a form for editing a resource, or maybe a popup box asking
            the user to confirm deleting a resource, or open a new page for the user to view
            a resource.
             */
        this.$store.commit(actionName, this.data);
        // this.$store.dispatch(actionName, this.data);
        console.log(actionName, this.data);
      },
    },
    props: {
      data: {
        type: Object,
        required: true,
      },
    },
  };
</script>

<style scoped></style>

Documentation on the bootstrap dependency

Following the setup, it suggested the requirement to:
import "bootstrap/dist/css/bootstrap.min.css";

It would be very useful to know which version of bootstrap is currently supported.
I don't see such a dependency from the module's package.json neither.

How can I access to data from nested object?

This is my data (books array) from my Request backend:

export default {
  name: "Books",
  data() {
    return {
      books: [
        {
            name: "Book 1",
            editorial: "Porrua",
            authors:{ 
               name: "Name author 1",
               age: 55,
               email: "[email protected]"
            },
       },
       {
            name: "Book 2",
            editorial: "Salamanca",
            authors:{ 
               name: "Name author 2",
               age: 34,
              email: "[email protected]"
            }
       }
    ]
    }
  },
  computed: {
    
    parameters() {
      return {
        data: this.books,
        lang: "es",
        actionMode: "single",
        columns: [
          {
            key: "name", //
            title: "Book",
          },
          {
            key: "authors.name", // try to access value but in the datatable the data is empty and if only the key is authors show [object] : authors:{name: "Name author 1",age: 55,email:"[email protected]"} 
            title: "Author",
          },
          {
            key: "editorial",
            title: "Editorial",
            sortable: false,
          },
        ],
      };
    },
  },
}

I try to access the author's data but i can't.
I only share two objects in the array but they can be more :(

Can you help me?

Save to a Latin :)

Vue3

I'm trying to use this package with vue 3 on my project and I get this error
Uncaught (in promise) TypeError: Cannot read property '_c' of undefined

Code:

<template>
    <app-layout>
        <template #header>
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                Clients
            </h2>
        </template>

        <div class="py-12">
            <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
                <div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
                    <div class="m-10 ">
                        <data-table v-bind="bindings"/>
                    </div>
                </div>
            </div>
        </div>
    </app-layout>
</template>

<script>
import AppLayout from '@/Layouts/AppLayout'
import DataTable from '@andresouzaabreu/vue-data-table';
import "@andresouzaabreu/vue-data-table/dist/DataTable.css";

export default {
    components: {
        AppLayout,
        DataTable
    },
    props: ['clients'],
    computed: {
        bindings() {
            return {
                columns: [
                    {
                        key: "name",
                    },
                    {
                        key: "email",
                        title: "Email Address",
                        sortable: false,
                    },
                ],
                data: this.clients
            }
        }
    }
}
</script>

How I add customize Column like S.No

i tried like
```
{
key:'index',
title:'S.No',
sortable: false,
},

Expected behaviour
 To display the ### S.No column and if i'm in search the ### S.No value must be rearrange

"Insert" functionality

First of all, thanks for the phenomenal work.
However, is there a way to add an insert functionality to this data table? For instance, the user may want to add a fruit manually to the fruit table when the user has no access to the source code.
Thanks!

Action Button cant modify the text column and its icons

I tried to follow the instructions and setup luckily it works but not fully, currently I am using Vue js version 2.6, I want to modify the design of the action button, but it doesn't work as expected, I think this is a bug in the package. please consider some modification in the action button like the font awesome icon and its action name, thank you, the best vue data-table that ive use so far

[FEATURE] .d.ts

Could not find a declaration file for module '@andresouzaabreu/vue-data-table'. 

How can i add emit to data-table component?

i am trying to add emit from custom-component but the problem I don't know how can I add it to a data comes from database.

this is the component. i don't know if this is the correct way to add emit
<data-table v-bind="parametersTable1" @toggle-details="toggleDetailsStatus" />

This is the data
data() { return { requestArray: [{id: 1},{id: 2}], }; },

This is the method
methods: { toggleFavoriteStatus(){ alert('uwu') }, },

I hope you can help me. thanks and stay safe guys

Action button doesn't show

I'am using vue version 2.6.12. I've already follow the code example on demo 1 and make sure that included actionMode: "single". How to show the action button or using template inside table like bootstrap table ?

Download Search Or Filtered Result Data on Table

Let's say i have 100 products data loaded in to vue-data-table. Now i am sorting products by price and table will change right? from initial table data to sorted by price data right? If i download now than It will give me initial data not sorted by price data! So how can i download those sorted by price data!

Column relationship

How could I display a field from a collection that comes with related data from another table.

{
key: "category.name",
title: "Category",
},

HTML in data / table cell

I was wondering if there is a way to render HTML inside the table when that HTML is present in the data served to the Vue DataTable.

I saw in demo 2 that for version 2 of this plugin you had actions that were HTML buttons.
This is my current configuration:

return { columns: [ { key: "name", title: 'Name' }, { key: "id", title: 'Relation ID' }, { key: "actions", title: 'Actions', sortable: false }, ], data: this.data, showPagination: false, defaultPerPage: 50, showEntriesInfo: false, showPerPage: false, showDownloadButton: false, }

this.data has objects that contains HTML to show actions (2 anchors that link to another page, which is now shown as text instead of clickable links.

Is it possible to add a property to a column say: html: true and if enabled it will render HTML found in the string as HTML instead of showing the code as text.

Customize configuration : tableWrapper (Not Working)

I am trying to implement this, package which is working fine.
Here is the problem i am facing :
tableWrapper

It looks like tableWrapper classes are not rendering properly,

.....
computed: {
        tableParams: function() {
            return {
                data: this.users,
                actionMode: "single",
                actions: ["action"],
                columns: [
                    {
                        key   : "first_name",
                        title : 'First Name',
                        sortable: true,
                        searchable: true,
                    },
                    {
                        key   : "last_name",
                        title : 'Last Name',
                        sortable: true,
                        searchable: true,
                    },
                    {
                        key   : "email",
                        title : "Email address",
                        sortable: true,
                        searchable: true,
                    }
                ],
                actionComponents:{
                    "action"   : ActionButtons,
                },
                defaultPerPage : 5,
                showPerPage : true,
                showEntriesInfo : true,
                showSearchFilter : true,
                showPagination : true,
                showDownloadButton : true,
                sortingMode : "single",
                allowedExports : ["xls", "csv", "json", "txt"],
                unsafeHTML : false,
                tableClass : "table table-separate table-head-custom table-checkable dataTable no-footer",
                tableWrapper : "dataTables_wrapper dt-bootstrap4 no-footer",
                perPageSizes : [5, 10, 30, 50, 70, 90, 110, 130, 150],
                text:{
                    emptyTableText : "No Users Found.",
                    actionsText : {
                        "*": "Actions",
                    }
                }
            };
        }
    },
.....

Description in the document says :

tableWrapper String data-table-wrapper The css classes of the table's wrapper

Is this suppose to happen ?

need help

Hello there,
how can add edit and delete button in this package ? I use laravel and vue just

Thanks

Component is not replacing original value

When I use the component column option and pass in a component, both the new component and original span show up in the table. This is adding duplicate values.
image

EDIT:: When I remove the "key" from the column object, it removes the extra value. This is contradictory to the example in the readme. It also removes the searching from that column

Customizing configurations not working

Let me be the first to leave an issue. I really love what you are doing, especially leaving jQuery out of it.

My issue: Most customizing configurations are not working, especially those at the bottom, cannot change :showExportButton, infoText, previousButtonText, nextButtonText.

Also, it would be great if I could specify position, for example if I could place the showing entries at the bottom.

Kudos, continue working on this great project

Custom Component

When Custom Componet is Add i.e. Footer Component but ican't display. As per your code add but not reflect

`


<data-table v-bind="parameters" @actionTriggered="handleAction" />

<script> import ImageTable from './ImageTable.vue'; import statusBadge from './statusBadge.vue'; import TableFooter from './TableFooter.vue' export default { name: 'TableDefault', props: { tableData: { type: Array, required: true }, is_search: { type: Boolean, required: true }, showAction:{ type:Boolean, required:false, default:false }, columns:{ required:false, type:Array, default:function(){ return [ { key: 'project', title: 'Project', sortable: false, component: ImageTable, }, { key: 'funding', title: 'Your Funding', sortable: false, }, { key: 'date', title: 'Funding Date', sortable: false, }, { key: 'status', title: 'Project Status', sortable: false, component: statusBadge, } ]; } }, }, data() { return { }; }, components: {}, computed: { parameters() { return { // data: [], // pass the empty array to see message data: this.tableData, lang: 'en', actionMode: 'single', perPageSizes: [5, 25, 50, 100], defaultPerPage: 5, showPerPage: false, showEntriesInfo: false, showSearchFilter: this.is_search, showDownloadButton: false, tableClass: 'table table-default table-hover table-borderless', columns: this.columns, footerComponent: TableFooter, }; }, }, methods: { handleAction(action, payload) { window.alert('check out the console to see the data logged'); } }, }; </script> <style lang="scss"> @import '../assets/scss/components/table.scss'; </style>

`

Possible add Line number ?

I want to add Line number of # column
Please help. It's possible ?

===========================
|   #    |       Name     |
---------------------------
|   1    |     Jane       |   
|   2    |     Jones      |  
|   3    |     John       |   
|   .    |     Jack       | 
|   .    |     jame       | 
|   .    |      ...       | 

is this usable WITHOUT NPM?

figured this would be a better place to ask you than on your Vue Forum post...

i often have to work within very narrow constraints for security purposes. consequently on some jobs, NPM, SASS are not available because we are only permitted to run locally linked libraries. nothing that can 'phone home'. not being familiar with NPM to the degree i'd like, i want to use your library, but don't know how to use it outside of an NPM-capable environment. is there a way to implement your wonderful tool locally sans NPM?

thanks for your patience.

Questions about maintainability

Hey! Thanks for your project! I always have concerns about integrating libraries that are only maintained by a single person, because they often get abandoned eventually. Can I ask how regular updates to the DataTables.net library will be incorporated into your port? Is there a streamlined process to do this or does it take a lot of manual labor to accomplish?

is it possible to set perpagesize into [10, 25, 50, 100, **ALL**]

Hello sir Andre, first of all this is not an issue this is just a question.

I just want to ask if it is possible to set perpagesize into [10, 25, 50, 100, ALL]
because i have a dynamic data and sometimes it exceeds the given size per page.
i am using the export to csv but it limits the row of data that i wanna export.
right now i am using perpagesize = [10, 25, 50, 100, 10000] since i my data doesn't exceed 10000.

Hope you can help me again. 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.