SlickGrid

repository·master·Indexed 24 days ago

https://github.com/6pac/slickgrid

A high-performance JavaScript grid and spreadsheet library designed for high-density data visualization. This modernized fork (6pac/slickgrid) features TypeScript migration, ESM/IIFE support, and a modern Alpine theme. Key capabilities include adaptive virtual scrolling for hundreds of thousands of rows, frozen columns/rows, advanced plugins like RowDetail and CellMenu, and extensive column management including resizing, reordering, and custom formatters/editors.

Tokens
13.5K
Snippets
10
Records
41
Agent score
85%

What's inside slickgrid

  1. Overview of SlickGrid features

    master

    SlickGrid is an advanced JavaScript grid/spreadsheet component designed for high performance and deep customization. It is particularly well-suited for applications requiring high-density data visualization and manipulation.

    Key capabilities include:

    • High Performance: Adaptive virtual scrolling allows for handling hundreds of thousands of rows with extreme responsiveness and fast rendering speeds.
    • Column Management: Supports resizing, reordering, showing, hiding, autosizing, and force-fitting columns.
    • Extensibility: Features pluggable cell formatters and editors, background post-rendering for rich cells, and support for grouping, filtering, and custom aggregators.
    • Data Editing: Supports editing and creating new rows, including advanced detached and multi-field editors with undo/redo support.
    • Concurrency Management: Includes a GlobalEditorLock to manage concurrent edits when multiple Views on a single page are editing the same data.
    • Styling: Supports jQuery UI Themes.
  2. How to use SlickGrid with Frameworks (Angular, React, Vue)

    master

    While SlickGrid provides an ES6/ESM build that works with most frameworks, it is highly recommended to use Slickgrid-Universal if you are working with:

    • Angular
    • React
    • Vue

    Slickgrid-Universal provides official wrappers specifically designed for these frameworks.

  3. Install SlickGrid via CDN (Alpine style and IIFE)

    master

    You can use SlickGrid as a standalone library by including scripts and styles directly from a CDN.

    1. Add the Alpine Theme

    Include the CSS link in your HTML <head> to use the modern Alpine look:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/styles/css/slick-alpine-theme.min.css">

    2. Include Standalone Scripts (IIFE)

    Load the core, interaction, and grid scripts in order:

    <script src="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/browser/slick.core.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/browser/slick.interactions.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/browser/slick.grid.min.js"></script>

    3. Initialize the Grid

    Once the scripts are loaded, you can instantiate the grid using the Slick global object:

    <script>
      const grid = new Slick.Grid("#myGrid", dataView, columns, options);
    </script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/styles/css/slick-alpine-theme.min.css">
    
    <script src="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/browser/slick.core.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/browser/slick.interactions.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/slickgrid@5.17.0/dist/browser/slick.grid.min.js"></script>
    <script>
      const grid = new Slick.Grid("#myGrid", dataView, columns, options);
    </script>
  4. Configure the SortableJS dependency

    master

    SlickGrid requires SortableJS as its only hard dependency. You must provide this dependency yourself depending on your environment.

    Using a Standalone <script>

    Include the script in your HTML:

    <script src="https://cdn.jsdelivr.net/npm/sortablejs/Sortable.min.js"></script>

    Using CJS or ESM

    If you are using a module bundler, you must manually assign the imported Sortable to the global window (or global for Node) object so SlickGrid can access it:

    import Sortable from 'sortablejs';
    (window as any).Sortable = Sortable;
    import Sortable from 'sortablejs';
    (window as any).Sortable = Sortable;
  5. Install SlickGrid via NPM (CJS/ESM)

    master

    For modern build pipelines, install SlickGrid via npm. It is recommended to use ESM import to enable tree shaking.

    1. Install the package

    npm install slickgrid

    2. Usage Example

    Import the styles and the necessary classes (SlickGrid, SlickDataView) in your module:

    import 'slickgrid/dist/styles/css/slick-alpine-theme.css';
    import { SlickGrid, SlickDataView } from 'slickgrid';
    
    const dataView = new SlickDataView({ inlineFilters: true });
    const grid = new SlickGrid("#myGrid", dataView, columns, options);
    npm install slickgrid
    
    <script type="module">
      import 'slickgrid/dist/styles/css/slick-alpine-theme.css';
      import { SlickGrid, SlickDataView } from 'slickgrid';
      const dataView = new SlickDataView({ inlineFilters: true });
      const grid = new SlickGrid("#myGrid", dataView, columns, options);
    </script>
  6. Configure Row Heights and Variable Row Heights

    master

    SlickGrid supports both fixed and variable row heights.

    • Fixed Row Height: Set the rowHeight option (defaults to a value determined by the grid, but you can specify it in pixels).
    • Variable Row Height: To enable rows with different heights, set enableVariableRowHeight: true.
    • Row Height Provider: When enableVariableRowHeight is enabled, you can provide a rowHeightProvider function. This function is called for each row and should return the height in pixels or undefined to fall back to the default rowHeight.

    Note: The rowHeightProvider must be fast and perform no DOM access, as it is called during height calculations and caching.

  7. Ensure CSP compliance when using HTML in formatters

    master

    Since version v5.5.0, SlickGrid is largely Content Security Policy (CSP) compliant. However, if you use custom formatters that return HTML strings, you will not be fully compliant unless you return TrustedHTML.

    To achieve compliance:

    1. Use the sanitizer grid option callback.
    2. Combine it with DOMPurify to return TrustedHTML.
  8. Configure Sorting and Multi-Column Sort

    master

    Control how data is sorted in the grid:

    • Multi-Column Sort: Set multiColumnSort: true to allow sorting by multiple columns (typically using Shift+Click).
    • Tristate Multi-Column Sort: Set tristateMultiColumnSort: true to enable multiple column sorting without needing to hold modifier keys.
    • Sort Indicators: sortColNumberInSeparateSpan (defaults to true) renders the sort precedence number in a separate span with the CSS class slick-sort-indicator-numbered.
  9. Configure Column Freezing (Pinning)

    master

    You can freeze (pin) columns or rows to keep them visible while scrolling.

    • Freeze Columns: Set frozenColumn to the number of columns to freeze from the left.
    • Freeze Rows: Set frozenRow to the number of rows to freeze from the top.
    • Freeze Bottom: Set frozenBottom: true to freeze the bottom portion of the grid instead of the top.
    • Validation: If you freeze columns that are wider than the visible viewport, the grid may trigger invalidColumnFreezeWidthCallback or invalidColumnFreezePickerCallback depending on your configuration.
  10. Configure Rendering and Security

    master

    Customize how data is displayed and ensure security:

    • HTML Rendering: Set enableHtmlRendering: true to allow passing HTML strings to cells/rows (uses innerHTML). For strict CSP compliance, set this to false and have your formatters return HTMLElement objects instead.
    • Sanitization: Provide a sanitizer: (dirtyHtml: string) => string function to clean HTML strings before rendering to prevent XSS.
    • Custom Tooltips: Use customTooltip to define tooltip behavior. The grid checks the column definition first, then falls back to the GridOption.