e-virt-table

repository·main·Indexed 41 days ago

https://github.com/laichuangwen/e-virt-table

A high-performance, canvas-based data grid library designed to emulate spreadsheet applications like Microsoft Excel or Google Sheets. Version 1.4.16 features virtual scrolling, cell editing, and extensive customization for borders, scrollbars, and font styles. It provides a comprehensive API for data management, validation, and lifecycle interception via methods like beforeValueChange and batchSetItemValue.

Tokens
39K
Snippets
124
Records
208
Agent score
52%

What's inside e-virt-table

  1. Overview of e-virt-table features

    main

    e-virt-table is a high-performance data table built on HTML5 Canvas. It is designed to function as a versatile data grid, similar to Microsoft Excel or Google Sheets, and is suitable for handling large datasets through virtual scrolling.

    Key features include:

    • Canvas-Based Rendering: Provides high performance and smooth interactions by leveraging canvas for rendering.
    • Virtual Scrolling: Efficiently handles large datasets by only rendering visible areas.
    • Cell Editing: Supports direct cell manipulation.
    • Multi-Framework Support: Compatible with Vue 3, Vue 2, React, and vanilla JavaScript.
  2. Overview of e-virt-table

    main

    e-virt-table is a powerful data table implementation based on HTML5 Canvas. It is designed to function as a high-performance data grid, similar to Microsoft Excel or Google Sheets. Key features include:

    • Virtual Scrolling: Efficiently handles large datasets by rendering only visible cells.
    • Cell Editing: Supports direct interaction and modification of cell data.
    • Canvas-based Rendering: Provides high performance for complex data grids.
  3. Understand the Value Change Lifecycle

    main

    When a user edits a cell, the following sequence occurs:

    1. Built-in number/length checks
    2. canValueChange (column-level gate)
    3. BEFORE_VALUE_CHANGE_METHOD (table-level value modification)
    4. Write operation
    5. Validators
    6. valueChange (column-level) or change (table-level) callbacks.

    Note: BEFORE_VALUE_CHANGE_METHOD is used to transform or change the assigned value, whereas formatters are typically for display only.

  4. Understand Tree Selection Modes

    main

    The TREE_SELECT_MODE configuration determines how selection propagates between parents and children:

    • Auto Mode (Default): Child items and semi-selected items are treated as selected. This behavior is reflected in the selectionChange event.
    • Cautious Mode: Semi-selected states are NOT treated as selected in the selectionChange event.
    • Strictly Mode: Parent and child items are completely independent. Selecting a parent does not affect children, and vice versa.
  5. Understand the Inner Scrollbar Hover-Only Design

    main

    In the inner scrollbar mode, scrollbars act as overlay elements that appear only when needed, rather than having manual collapse/expand controls.

    Behavioral Model:

    1. Hidden State: Inner scrollbars start hidden by default.
    2. Hover Trigger: Moving the pointer inside the table triggers a delay defined by SCROLLBAR_SHOW_DELAY. After this delay, the vertical and horizontal scrollbars are drawn over the table content.
    3. Persistence: Scrollbars remain visible if the table has focus or if the user is currently dragging a scrollbar thumb.
    4. Auto-Hide: When the pointer leaves the table area, any pending show timers are cleared and the scrollbars are hidden (unless a drag operation is in progress).
    5. No Manual Toggles: There are no DOM elements for toggling the visibility of inner scrollbars; interaction is purely pointer-driven.

    Note that this behavior is specific to inner mode. The outer scrollbar mode remains unaffected and continues its existing visibility logic.

  6. Understand Scrollbar Visibility Logic

    main

    When scrollbarMode is set to inner, the visibility of the scrollbars is determined by a combination of state flags. The scrollbars are drawn if any of the following conditions are met:

    1. innerVisible: The scrollbar is currently in its visible state (triggered by hover).
    2. isFocus: The table or scroller has focus.
    3. isDragging: The user is currently dragging a scrollbar thumb.

    If scrollbarMode is NOT set to inner, the scrollbars follow the default visibility rules.

  7. Use adaptive row height

    main

    Adaptive row height is disabled by default. When enabled, rows expand to fit their content.

    Important Notes:

    • If using an overlay DOM for adaptive height, you must set domDataset.
    • Because the table calculates row height based on the visible area, you may observe some 'jumping' during scrolling; this is expected behavior.
    • To prevent rows from expanding excessively, use the maxLineClamp parameter in your column configuration to truncate text.
  8. Understand border style layout constraints

    main

    When configuring BORDER styles, be aware of the following layout and dimension constraints:

    • Fixed Dimensions: Border width is fixed at 1 and color is fixed at BORDER_COLOR.
    • No Layout Impact: Changing the border style does not affect calculations for:
      • Column width
      • Row height
      • Auto-row-height calculations
      • Header.init() width or height totals
      • Body.update() row positions
      • Database.getData() row positions and sumHeight
      • Paint.calculateTextHeight()
      • Row.updateCalculatedHeight()
    • Excluded Elements: The BORDER setting does not control the appearance of selection lines, autofill, validation, drag/resize handles, hover-icons, or tree guide lines.
  9. Implement Merging Data Association

    main

    When using merging techniques, you can choose between unassociated merging and Merge Data Association.

    Merge Data Association

    In this mode, merged cells are logically linked. If the data in one of the merged cells changes, the change is automatically reflected in all other related cells within that merged group.

    Important Considerations

    • Data Integrity: Because cells are linked, operations like copying, pasting, or filling cells may trigger error prompts to prevent data inconsistency.
    • Error Handling: If you wish to replace the system's default error prompt box with a custom UI, you should listen to the error event emitted by the table.
  10. Understand Virtual Scrolling behavior in e-virt-table

    main

    By default, e-virt-table enables virtual scrolling for both rows and columns without requiring any additional configuration. This allows the table to handle large datasets, supporting more than 200,000 data entries efficiently.

    To optimize performance, keep the number of visible cells as low as possible. While the virtualization engine is highly efficient, extremely large datasets may still be limited by network latency or the client's memory capacity.