All Projects β†’ bsssshhhhhhh β†’ Svelte Data Grid

bsssshhhhhhh / Svelte Data Grid

Licence: mit
Lightweight and powerful data grid for svelte

Projects that are alternatives of or similar to Svelte Data Grid

Svelte Frappe Charts
πŸ“ˆ Svelte bindings for frappe-charts.
Stars: ✭ 111 (-20.14%)
Mutual labels:  svelte
Svelte Tags Input
Svelte tags input is a component to use with Svelte and easily enter tags and customize some options
Stars: ✭ 123 (-11.51%)
Mutual labels:  svelte
Svelte Simple Modal
A simple, small, and content-agnostic modal for Svelte v3
Stars: ✭ 130 (-6.47%)
Mutual labels:  svelte
Fe News
FE 기술 μ†Œμ‹ νλ ˆμ΄μ…˜ λ‰΄μŠ€λ ˆν„°
Stars: ✭ 2,249 (+1517.99%)
Mutual labels:  svelte
Figma Theme Ui
Convert a Theme UI config to Figma Styles
Stars: ✭ 122 (-12.23%)
Mutual labels:  svelte
Svelte Loading Spinners
A collection of loading spinner components for SvelteJs
Stars: ✭ 125 (-10.07%)
Mutual labels:  svelte
Sapper Firebase Typescript Graphql Tailwindcss Actions Template
A template that includes Sapper for Svelte, Firebase functions and hosting, TypeScript and TypeGraphQL, Tailwind CSS, ESLint, and automatic building and deployment with GitHub Actions
Stars: ✭ 111 (-20.14%)
Mutual labels:  svelte
Routify Starter
Stars: ✭ 137 (-1.44%)
Mutual labels:  svelte
Svelte Material Ui
Svelte Material UI Components
Stars: ✭ 2,081 (+1397.12%)
Mutual labels:  svelte
Sveltik
Powerful forms in Svelte, inspired by Formik.
Stars: ✭ 128 (-7.91%)
Mutual labels:  svelte
Perf Track
Tracking framework performance and usage at scale
Stars: ✭ 116 (-16.55%)
Mutual labels:  svelte
Vime
Customizable, extensible, accessible and framework agnostic media player. Modern alternative to Video.js and Plyr. Supports HTML5, HLS, Dash, YouTube, Vimeo, Dailymotion...
Stars: ✭ 1,928 (+1287.05%)
Mutual labels:  svelte
Svelte Navigator
Simple, accessible routing for Svelte
Stars: ✭ 125 (-10.07%)
Mutual labels:  svelte
Svelte Firebase
A template to help you start developing SPAs with Svelte and Firebase.
Stars: ✭ 111 (-20.14%)
Mutual labels:  svelte
Nanocal
Airbnb range picker rip-off
Stars: ✭ 132 (-5.04%)
Mutual labels:  svelte
Cypress Svelte Unit Test
Unit testing Svelte components in Cypress E2E test runner
Stars: ✭ 110 (-20.86%)
Mutual labels:  svelte
Codesandbox Client
An online IDE for rapid web development
Stars: ✭ 11,122 (+7901.44%)
Mutual labels:  svelte
Xsm
State Management made eXtraordinarily simple and effective for Angular, React, and Vue
Stars: ✭ 138 (-0.72%)
Mutual labels:  svelte
Tsparticles
tsParticles - Easily create highly customizable particles animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components.
Stars: ✭ 2,694 (+1838.13%)
Mutual labels:  svelte
Svelte Forms
Svelte forms validation made easy
Stars: ✭ 127 (-8.63%)
Mutual labels:  svelte

npm

Svelte Data Grid

Demo

Svelte Data Grid is a svelte v3 component for displaying and editing any amount of data.

Features:

  • Excellent scrolling performance
  • ARIA attributes set on elements
  • Lightweight even when displaying a huge dataset due to implementation of a "virtual list" mechanism
  • Column headers remain fixed at the top of the grid
  • Custom components can be specified to control how individual table cells or column headers are displayed
  • Columns can be resized and reordered

Current Limitations:

  • Every row must have the same height and text cannot break onto the next line

Usage:

If using within Sapper:

npm install svelte-data-grid --save-dev

If using from inside a svelte component:

import DataGrid from "svelte-data-grid";
<DataGrid rows={myRows} allowColumnReordering={false} columns={myColumnDefinitions} on:columnOrderUpdated={saveNewColumnOrder}>

If using from outside svelte:

import DataGrid from "svelte-data-grid";
const grid = new DataGrid({
  target: document.querySelector('#my-grid-wrapper'),
  data: {
    rows: [ ... ],
    columns: [ ... ],
    allowResizeFromTableCells: true
  }
});

grid.$on('columnOrderUpdated', () => {
  const { columns } = grid.get();
  // save new column  order
});

To learn more about using DataGrid outside of svelte, read svelte's guide on how to interact with a svelte component. It is possible to integrate into any framework.

DataGrid requires 2 properties to be passed in order to display data: rows and columns.

columns is an array of objects containing at least 3 properties: display, dataName, and width. A svelte component can be specified in headerComponent and cellComponent if any custom cell behavior is required.

[
  {
    display: 'Fruit Name',  // What will be displayed as the column header
    dataName: 'fruitName',  // The key of a row to get the column's data from
    width: 300,             // Width, in pixels, of column
    disallowResize: true    // Optional - disables resizing this column
  },
  {
    display: 'Color',
    dataName: 'fruitColor',
    width: 600,
    myExtraData: 12345
  }
]

rows is an array of objects containing the data for each table row.

[
  {
    fruitName: 'Apple',
    fruitColor: 'Red'
  },
  {
    fruitName: 'Blueberry',
    fruitColor: 'Blue'
  },
  {
    fruitName: 'Tomato',
    fruitColor: 'Red'
  }
]

Editing Data

Version 2 added early support for editing data. Due to the lack of using a keyed each block to render the rows, maintaining focus on controls as the user scrolls is a tad wonky. This will be resolved in a future version.

Import the components:

import TextboxCell from 'svelte-data-grid/src/textbox-cell.svelte';
import SelectCell from 'svelte-data-grid/src/select-cell.svelte';
import CheckboxCell from 'svelte-data-grid/src/checkbox-cell.svelte';

Textbox Cell

Textbox cell will debounce the user input, only recording changes after 400ms has elapsed since the user stops typing.

{
  display: 'Name',
  dataName: 'name',
  width: 250,
  cellComponent: TextboxCell
}

Select Cell

SelectCell requires that you provide an options array in your cell definition:

{
  display: 'Eye Color',
  dataName: 'eyeColor',
  width: 75,
  cellComponent: SelectCell,
  options: [
    {
      display: 'Green',
      value: 'green'
    },
    {
      display: 'Blue',
      value: 'blue'
    },
    {
      display: 'Brown',
      value: 'brown'
    }
  ]
}

Checkbox Cell

CheckboxCell will set the checked state of the checkbox depending on the boolean value of the row's data.

{
  display: 'Active',
  dataName: 'isActive',
  width: 75,
  cellComponent: CheckboxCell
}

Custom Cell Components

Need to customize how your data is displayed or build more complex functionality into your grid? Specify cellComponent in your definition in the columns property.

Components will be passed the following properties:

  • rowNumber - The index of the row within rows
  • row - The entire row object from rows
  • column - The entire column object from columns

MyCustomCell.svelte

<script>
export let data = {
  colors: {
    Red: '#FF0000',
    Blue: '#0000FF'
  }
};
</script>

<div style="color: {colors[row.data[column.dataName]] || 'black'};">
  {row.data[column.dataName]}
</div>

Import the component

import MyCustomCell from './MyCustomCell.svelte';

columns option:

[
  {
    display: 'Fruit Color'
    dataName: 'fruitColor',
    width: 300,
    cellComponent: MyCustomCell
  }
]

Custom Header Components

Header components can also be specified in columns entries as the headerComponent property. Header components are only passed column, the column object from columns.

Options:

Svelte Data Grid provides a few options for controlling the grid and its interactions:

  • rowHeight - The row height in pixels (Default: 24)
  • allowResizeFromTableCells - Allow user to click and drag the right border of a table cell to resize the column (Default: false)
  • allowResizeFromTableHeaders - Allow user to click and drag the right border of a column header to resize the column (Default: true)
  • allowColumnReordering - Allow user to drag a column header to move that column to a new position (Default: true)
  • allowColumnAffix - Allow user to drag the double line to affix columns to the left side of the grid. See section below for caveats (Default: true if the browser is chrome, false otherwise)
  • __extraRows - If it is desired that the virtual list include more DOM rows than are visible, the number of extra rows can be specified in __extraRows (Default: 0)
  • __columnHeaderResizeCaptureWidth The width of the element, in pixels, placed at the right border of a column that triggers that column's resize. (Default: 20)

Events:

  • columnOrderUpdated - Fired when the user has dragged a column to a new position. The updated column order can be accessed from component.get().columns
  • columnWidthUpdated - Fired when a user has resized a column. The updated column width can be accessed from event.width and the column index can be accessed from event.idx

Column Affixing

This feature works well on Chrome because Chrome's scroll events are not fired asynchronously from the scroll action. Firefox, Edge, and IE all fire scroll events after the overflow container has scroll on screen. This causes a jittery effect that we cannot easily work around while providing a cross-browser solution.

To fix the jitteriness on Firefox, a setting in about:config can be changed to turn off APZ. Set layers.async-pan-zoom.enabled to false. Obviously this is not a solution we can reasonably ask users to try, so I'm looking for other solutions.

Bugs? Suggestions?

Feedback is always appreciated. Feel free to open a GitHub issue if DataGrid doesn't work the way you expect or want it to.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].