New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@marketconnect/vue-pivot-table

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@marketconnect/vue-pivot-table

A vue component for pivot table

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

vue-pivot-table

A vue component for pivot table

vue-pivot-table screenshot

Live demo (jsfiddle)

Install

npm install --save @marketconnect/vue-pivot-table

Usage

This project includes 2 components:

  • PivotTable: a component to create an aggregation table from data + row/column settings
  • Pivot : a PivotTable wrapper with drag & drop user interface to set rows/columns

While the Pivot component provides the full experience, the PivotTable can be used standalone.

Browser

Vue.use(VuePivot)

Webpack

PivotTable

Javascript
import PivotTable from '@marketconnect/vue-pivot-table'

export default {
  components: { PivotTable },

  // Basic data for component props
  data: () => {
    return {
      data: Object.freeze([{ x: 0, y: 0, z: 0 }, { x: 1, y: 1, z: 1 }]),
      rowFields: [{
        getter: item => item.y,
        label: 'Y'
      }, {
        getter: item => item.z,
        label: 'Z'
      }],
      colFields: [{
        getter: item => item.x,
        label: 'X'
      }],
      reducer: (sum, item) => sum + 1
    }
  }
  ...
}
HTML
<pivot-table :data="data" :row-fields="rowFields" :col-fields="colFields" :reducer="reducer">
  <!-- Optional slots can be used for formatting table headers and values, see documentation below -->
</pivot-table>

Pivot

Javascript
import Pivot from '@marketconnect/vue-pivot-table'

export default {
  components: { Pivot },

  // Basic data for component props
  data: () => {
    return {
      data: Object.freeze([{ x: 0, y: 0, z: 0 }, { x: 1, y: 1, z: 1 }]),
      fields: [],
      rowFields: [{
        getter: item => item.y,
        label: 'Y'
      }, {
        getter: item => item.z,
        label: 'Z'
      }],
      colFields: [{
        getter: item => item.x,
        label: 'X'
      }],
      reducer: (sum, item) => sum + 1
    }
  }
  ...
}
HTML
<pivot :data="data" :fields="fields" :row-fields="rowFields" :col-fields="colFields" :reducer="reducer">
  <!-- Optional slots can be used for formatting table headers and values, see documentation below -->
</pivot>

API

Note: internally, the Pivot component will pass down its props and slots to its PivotTable instance.

Props

PivotTable & Pivot
PropTypeDefaultDescription
dataArray[]Dataset to use in the pivot ; each element should be an object
row-fieldsArray[]Fields to use as rows by default
col-fieldsArray[]Fields to use as columns by default
reducerfunction(sum, item) => sum + 1Function applied to reduce data in the pivot table
no-data-warning-textString'No data to display.' Text to display when data is empty
is-data-loadingBooleanfalseDisplay a loading content instead of the table when the value is true (see slots for customization)
Pivot only
PropTypeDefaultDescription
fieldsArray[]Fields to display in the "Available fields" zone
default-show-settingsBooleantrueShow settings at component creation
available-fields-label-textString'Available fields' Text for available fields drag area
rows-label-textString'Rows' Text for the rows drag area
cols-label-textString'Columns' Text for the columns drag area
hide-settings-textString'Hide settings' Text for the "hide settings" button
show-settings-textString'Show settings' Text for the "show settings" button
Field format

Each element in the arrays fields, colFields or rowFields should be an Object with this format:

PropTypeDescription
labelStringText to display in the draggable button (Pivot only)
getterFunctionFunction to apply on an element of data to get the field value
sortFunctionOptional - Function to order fields in the pivot table header ; if no value is provided, javascript-natural-sort will be applied
showHeaderBooleanOptional (default: true) - Whether the header should be displayed in the pivot table
showFooterBooleanOptional (default: false) - Whether the footer should be displayed in the pivot table
headerSlotNameStringOptional - Name of the slot to use to format the header in the pivot table ; if no slot name is provided, the value will be displayed as found in data
footerSlotNameStringOptional - Same as above for the footer

Slots

Table headers

To customize table headers/footers, set a slot name on the field using headerSlotName/footerSlotname, then use the dynamically created slot:

<template v-slot:my-field-header-slot-name="{ value }">{{ value }}</template>
Cell values

Pivot table cell values can be customized with the value scoped slot:

<template v-slot:value="{ value }">{{ value.toLocaleString }}</template>

Currently this slot is applied to all value cells and does not allow customization based on current rowField/colField (TODO).

Loading

If the data prop is loaded asynchronously, a loading feedback can be displayed by setting the data-is-loading prop to true. The default feedback is the text "Loading...".

It can be customized with the loading slot:

<template v-slot:loading>Loading data, please wait...</template>
Computing

At the creation of the PivotTable component, and when the data/rowFields/colFields props change, a different loading feedback is displayed to the user. The default feedback is the text "Loading table values...".

It can be customized with the computing slot:

<template v-slot:computing>Loading table values, please wait...</template>

This feedback will be displayed together with the table in its previous state.

Large datasets

If this component is used with large datasets, consider applying Object.freeze on your data object to avoid useless change tracking on each data element.

See https://vuejs.org/v2/guide/instance.html#Data-and-Methods.

Build

# Install dependencies
npm install

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

# Build js libraries in dist folder
npm run build

Thanks

FAQs

Package last updated on 13 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc