VikCraft Interactive Data Table v3.0

A powerful JavaScript library for creating highly customizable, interactive data tables with column freezing, theme switching, virtual scrolling, keyboard navigation, CSV/Excel export, fullscreen mode, and much more.

View on GitHub View Details

Feature Toggles — Turn features on/off and click "Apply" to re-initialize the table.

Live Demo — All features enabled. Try: freeze columns, switch themes, keyboard arrows, fullscreen, export.

Component Details

  • Column FreezingFreeze first N columns so they stay visible while scrolling horizontally. Works with checkbox and row number columns.
  • Theme SwitcherSwitch between 6 built-in themes live: Light, Dark, Midnight, Blue, Green, and Compact.
  • Smart PaginationPage number buttons (1, 2, 3...) with ellipsis for large datasets — not just prev/next.
  • Row NumbersOptional auto-incrementing row numbers column.
  • Fullscreen ModeExpand the table to fullscreen for focused data work. Press ESC to exit.
  • Keyboard NavigationArrow keys to navigate between cells. Enter to edit. Tab-accessible.
  • Status BarFooter bar showing Sum, Avg, Min, Max for number columns and total row count.
  • Debounced SearchConfigurable debounce delay prevents excessive re-renders while typing.
  • CSV ExportExport filtered data to CSV alongside the existing Excel export.
  • Copy to ClipboardOne-click copy of table data (tab-separated) to clipboard.
  • Print ViewOpens a print-friendly window with the table data.
  • Loading IndicatorSpinner overlay shown during server-side data fetches.
  • Row HighlightingClick a row to highlight it. Selected rows have distinct styling.
  • Client-Side & Server-Side DataSeamlessly switch between local and API data processing.
  • Sorting & Global SearchClick headers to sort; use a single search box to filter across all columns.
  • Column FilteringAdvanced per-column filters: text, number, dropdown select, date range/comparison.
  • PaginationNavigate large datasets with customizable page lengths.
  • Column ResizingDrag column edges to adjust widths.
  • Multi-Level GroupingDrag columns to create nested grouping of rows.
  • Inline EditingClick cells to edit: text, number, dropdown, date, and checkbox inputs.
  • Row SelectionCheckboxes for individual and "select all" row selection.
  • Custom Actions & StylingAdd buttons, apply dynamic CSS classes per row or cell.
  • Excel ExportExport data to .xlsx with custom titles and subtitles.
  • Column VisibilityToggle columns on/off via a dropdown.
  • AI Data AssistantChat with AI about your data — ask questions, find insights, get summaries. Supports Anthropic API key (frontend) or backend proxy URL.

1. Include the Library Files

<!-- Required for Excel Export -->
<script src="https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.full.min.js"></script>

<!-- VikCraft DataTable -->
<link rel="stylesheet" href="vikcraft-data-table.css">
<script src="vikcraft-data-table.js"></script>

2. Initialize with All Features

const table = new VikCraftDataTable('#my-table', {
    data: myData,
    theme: 'dark',
    columns: [
        { key: 'id', label: 'ID', sortable: true, filterable: true, type: 'number' },
        { key: 'name', label: 'Name', sortable: true, filterable: true, editable: true },
        // ...
    ],

    // v3.0 Features
    freezeColumns: 2,           // Freeze first 2 data columns
    enableThemeSwitcher: true,   // Theme dropdown in toolbar
    enableRowNumbers: true,      // Show row numbers
    enableFullscreen: true,      // Fullscreen button
    enableCopyClipboard: true,   // Copy button
    enablePrint: true,           // Print button
    enableCsvExport: true,       // CSV export button
    enableStatusBar: true,       // Sum/Avg/Min/Max footer
    enableKeyboardNav: true,     // Arrow key navigation
    searchDebounceMs: 300,       // Debounce search input

    // Existing features
    enableCheckboxes: true,
    enableSearch: true,
    enableColumnFilter: true,
    enablePagination: true,
    enableGrouping: true,
    enableEditing: true,
    enableExcelExport: true,
    enableColumnVisibility: true,
});
OptionTypeDefaultDescription
dataArray[]Client-side data array
columnsArray[]Column definitions (required)
freezeColumnsnumber0Number of data columns to freeze from left
enableThemeSwitcherbooleanfalseShow theme switcher dropdown in toolbar
enableRowNumbersbooleanfalseShow auto-incrementing row numbers
enableFullscreenbooleanfalseShow fullscreen toggle button
enableCopyClipboardbooleanfalseShow copy to clipboard button
enablePrintbooleanfalseShow print button
enableCsvExportbooleanfalseShow CSV export button
enableStatusBarbooleanfalseShow footer with Sum/Avg/Min/Max
enableKeyboardNavbooleanfalseArrow key cell navigation
searchDebounceMsnumber250Debounce delay for search input (ms)
enableCheckboxesbooleantrueEnable row-selection checkboxes
enableEditingbooleanfalseMaster switch for inline editing
enableGroupingbooleantrueEnable drag-and-drop grouping
themestring'default'Initial theme: default, dark, midnight, blue, green, narrow
enableAIbooleanfalseEnable AI data assistant chat panel
aiConfig.apiKeystring''Anthropic API key (frontend mode)
aiConfig.backendUrlstring''Backend proxy URL for AI requests (keeps key server-side)
aiConfig.modelstring'claude-sonnet-4-20250514'Claude model to use

Each column definition supports these properties:

PropertyTypeDescription
keystringData object key (required)
labelstringColumn header text
sortablebooleanEnable column sorting
filterablebooleanShow filter input for this column
typestring'string', 'number', or 'date'
filterTypestring'dropdown' or 'date' for special filter UI
editablebooleanEnable inline editing (requires enableEditing: true)
editTypestring'text', 'number', 'date', 'dropdown', or 'checkbox'
renderfunction(value, row, col) => htmlString
cellStylerfunction(value, row) => ({ className, style })
visiblebooleanDefault: true. Set false to hide initially.

Column Freezing

Set freezeColumns: 2 to freeze the first 2 data columns. Checkbox and row number columns are automatically frozen when present.

new VikCraftDataTable('#table', {
    freezeColumns: 2,  // ID and Name columns stay fixed
    enableCheckboxes: true,  // Checkbox also stays fixed
    enableRowNumbers: true,  // Row # also stays fixed
    // ...
});

Theme Switcher

Enable enableThemeSwitcher: true to show a dropdown in the toolbar. Users can switch between Light, Dark, Midnight, Blue, Green, and Compact themes in real-time.

Smart Pagination

Pagination now shows actual page numbers (1, 2, 3 ... 10) with ellipsis for large page counts, instead of just previous/next buttons.

Debounced Search

Configure searchDebounceMs: 300 to add a 300ms debounce on the search input. This prevents excessive re-renders while the user is still typing, which is critical for large datasets.

Status Bar

Enable enableStatusBar: true to show a footer bar with Sum, Average, Min, and Max for all number-type columns, plus total row count.

Keyboard Navigation

Enable enableKeyboardNav: true and click the table to focus it. Then use Arrow keys to move between cells, and Enter to start editing an editable cell.

Copy, Print, CSV Export

Three new toolbar buttons for quick data export: Copy to Clipboard (tab-separated), Print (opens print-friendly window), and CSV Export (downloads .csv file).

AI Data Assistant

Enable enableAI: true to add an AI chat panel. Users can ask questions about their data and get instant analysis powered by Claude.

Two ways to configure the API key:

  • Frontend key: Set aiConfig.apiKey in config, or let users enter it via the settings gear icon. The key is stored in localStorage.
  • Backend proxy: Set aiConfig.backendUrl: '/api/ai-query' to route all AI requests through your server. This keeps your API key secure on the server side.
// Frontend API key mode
enableAI: true,
aiConfig: {
    apiKey: 'sk-ant-...',  // Or let user set via UI
    model: 'claude-sonnet-4-20250514',
}

// Backend proxy mode (recommended for production)
enableAI: true,
aiConfig: {
    backendUrl: '/api/ai-query',
    backendHeaders: { 'Authorization': 'Bearer mytoken' },
}

The backend should accept a POST with { messages, system, model, max_tokens, tableContext } and return { content: "response text" }.

When serverSide: true, the table fetches data from the ajax endpoint. A loading spinner is shown during requests.

Expected JSON Response

{
  "data": [{ "id": 1, "name": "Alice", ... }],
  "recordsTotal": 100,
  "recordsFiltered": 25,
  "isGrouped": false
}

Built-in Themes (6 total)

  • 'default' — Clean light theme
  • 'dark' — Dark gray theme
  • 'midnight' — Deep navy blue theme (NEW)
  • 'blue' — Light blue accents (NEW)
  • 'green' — Light green accents (NEW)
  • 'narrow' — Compact padding for dense data

Use setTheme('midnight') or the theme switcher dropdown to change themes at runtime.

Custom Row Styling

onRowCreate: function(rowData, tr) {
    if (rowData.salary === null) {
        tr.classList.add('row-inactive');
    }
}

Core Methods

  • setTheme(name) — Change theme ('default', 'dark', 'midnight', 'blue', 'green', 'narrow')
  • reloadData(newFilters) — Reload table data
  • addRow(object) — Add a row (client-side only)
  • toggleFullscreen() — Toggle fullscreen mode
  • exportToExcel() — Trigger Excel export
  • exportToCsv() — Trigger CSV export
  • copyToClipboard() — Copy data to clipboard
  • printTable() — Open print view

Grouping

  • setGroupBy(keys) — Set grouping (string or array)
  • addGroupKey(key) — Add to grouping stack
  • removeGroupKey(key) — Remove from grouping

Selection

  • getSelectedRows() — Get array of selected row data
  • clearColumnFilter(key) — Clear a column filter

AI

  • openAIPanel() — Open the AI chat panel
  • closeAIPanel() — Close the AI chat panel
  • setAIApiKey(key) — Set the API key programmatically (e.g. from your backend)