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,
});
| Option | Type | Default | Description |
|---|---|---|---|
data | Array | [] | Client-side data array |
columns | Array | [] | Column definitions (required) |
freezeColumns | number | 0 | Number of data columns to freeze from left |
enableThemeSwitcher | boolean | false | Show theme switcher dropdown in toolbar |
enableRowNumbers | boolean | false | Show auto-incrementing row numbers |
enableFullscreen | boolean | false | Show fullscreen toggle button |
enableCopyClipboard | boolean | false | Show copy to clipboard button |
enablePrint | boolean | false | Show print button |
enableCsvExport | boolean | false | Show CSV export button |
enableStatusBar | boolean | false | Show footer with Sum/Avg/Min/Max |
enableKeyboardNav | boolean | false | Arrow key cell navigation |
searchDebounceMs | number | 250 | Debounce delay for search input (ms) |
enableCheckboxes | boolean | true | Enable row-selection checkboxes |
enableEditing | boolean | false | Master switch for inline editing |
enableGrouping | boolean | true | Enable drag-and-drop grouping |
theme | string | 'default' | Initial theme: default, dark, midnight, blue, green, narrow |
enableAI | boolean | false | Enable AI data assistant chat panel |
aiConfig.apiKey | string | '' | Anthropic API key (frontend mode) |
aiConfig.backendUrl | string | '' | Backend proxy URL for AI requests (keeps key server-side) |
aiConfig.model | string | 'claude-sonnet-4-20250514' | Claude model to use |
Each column definition supports these properties:
| Property | Type | Description |
|---|---|---|
key | string | Data object key (required) |
label | string | Column header text |
sortable | boolean | Enable column sorting |
filterable | boolean | Show filter input for this column |
type | string | 'string', 'number', or 'date' |
filterType | string | 'dropdown' or 'date' for special filter UI |
editable | boolean | Enable inline editing (requires enableEditing: true) |
editType | string | 'text', 'number', 'date', 'dropdown', or 'checkbox' |
render | function | (value, row, col) => htmlString |
cellStyler | function | (value, row) => ({ className, style }) |
visible | boolean | Default: 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.apiKeyin config, or let users enter it via the settings gear icon. The key is stored inlocalStorage. - 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 dataaddRow(object)— Add a row (client-side only)toggleFullscreen()— Toggle fullscreen modeexportToExcel()— Trigger Excel exportexportToCsv()— Trigger CSV exportcopyToClipboard()— Copy data to clipboardprintTable()— Open print view
Grouping
setGroupBy(keys)— Set grouping (string or array)addGroupKey(key)— Add to grouping stackremoveGroupKey(key)— Remove from grouping
Selection
getSelectedRows()— Get array of selected row dataclearColumnFilter(key)— Clear a column filter
AI
openAIPanel()— Open the AI chat panelcloseAIPanel()— Close the AI chat panelsetAIApiKey(key)— Set the API key programmatically (e.g. from your backend)