npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

inertia-table

v1.0.8

Published

A Vue component for quickly and easily creating Inertia JS powered tables. Suggested usage with [Inertia table for Laravel](https://github.com/harmonic/inertia-table).

Downloads

17

Readme

Inertia JS Table for Vue

A Vue component for quickly and easily creating Inertia JS powered tables. Suggested usage with Inertia table for Laravel.

Laravel Preset - Click for video

Project setup

Requires Inertia JS to be installed in your project.

npm install --save inertia-table

or

yarn add inertia-table

Using inertia table

Installing globally

In your main js file:

import InertiaTable from 'inertia-table'
Vue.use(InertiaTable);

Using within a component

In your component .vue file

import InertiaTable from 'inertia-table'

export default {
  components: {
	InertiaTable,
	...
  },
  ...

Once installed simply use as any other component:

<inertia-table></inertia-table>

Configuration

The table can be configured with a number of paramaters:

| Paramater | Required | Type | Values | Default | Description | |------------|----------|--------|---------------------------------------------------------------------------------------------------|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | columns | No | Array | ['column1', 'column2'] | All columns in data array. | The name of the columns (found in the data array) to display in the table. | | data | Yes | Array | [ 'column1' => 'value1', 'column2' => 'value2' ] [ 'column1' => 'value3', 'column2' => 'value4' ] | None | The data that can be displayed in the table. | | id | No | String | "ID" | id | The name of the column that contains a unique ID. Used to identify a unique row for CRUD operations. | | routeName | Yes | String | "users" | None | The name of the Inertia JS route related to the data being displayed. | | createLink | No | String | "users.create" | null | The route name to follow (via an inertia-link) when create button is clicked. Will not display create button if set to null (default). | | filters | No | Object | { search: '', trashed: '' } | null | Data filter information returned from server (see Inertia Table for Laravel server example.) | | order | No | Object | { orderColumn: 'column1', orderDirection: 'asc' } | null | Select a column to order (by column name) and the direction to order (asc or desc). |

Custom columns

By default the table will look for the data value in your data array parameter. If you wish to format your column differently, or add additional columns to your table you can do this using Vue's scoped slots. Your slot name will be the column name and the row data is availabe in the column object. A basic example:

<inertia-table 
  :data="users" 
  id="id" 
  :order="order" 
  :filters="filters" 
  :columns="columns" 
  routeName="users" 
  createLink="users.create" 
  @item-selected="show">
    <template slot-scope="column" slot="company">
      {{ column.item.companyName }}
    </template>
</inertia-table>                                                     

In the above example we are creating a new column "company" (as per the slot attribute). The slot-scope attribute contains the column details so we can then display them however we want. You can simplify your code to access just the column item if you prefer:

<inertia-table 
  :data="users" id="id" 
  :order="order" 
  :filters="filters" 
  :columns="columns" 
  routeName="users" 
  createLink="users.create" 
  @item-selected="show">
    <template slot-scope="{ item }" slot="company">
      {{ item.companyName }}
    </template>
</inertia-table>                                                     

This technique allows you to completely customise what is displayed in any column of the table, this may include HTML or other Vue components, eg.

<inertia-table 
  :data="users" id="id" 
  :order="order" 
  :filters="filters" 
  :columns="columns" 
  routeName="users" 
  createLink="users.create" 
  @item-selected="show">
    <a slot-scope="{ item }" slot="subscription" :href="`/subscriptions?search=${item.id}`" class="underline" v-on:click.stop="">View</a>
</inertia-table>   

The above example generates an HTML link to display in a subscription column.

Events

| Event | Description | |---------------|--------------------------------------------------------------| | item-selected | Returns the details of the data row clicked on in the table. |

Example

The below example assumes you are using harmonic/inertia-table for Laravel to create a backend controller that handles delivery of a User array and filters/orders the data.

<inertia-table 
  :data="users" 
  id="id" 
  :order="order" 
  :filters="filters" 
  :columns="columns" 
  routeName="users" 
  createLink="users.create" 
  @item-selected="show">
</inertia-table>
<script>
import InertiaTable from 'inertia-table'

export default {
  components: {
    InertiaTable
  },
  props: {
    users: Array,
    filters: Object,
    order: Object,
  },
  data() {
    return {
      columns: ["name", "email"],
    }
  },
  methods: {
    show(user) {
      this.$inertia.replace(this.route('users.edit', user.id));
    }
  },
}
</script>