Slickgrid-Vue
Slickgrid-Vue is a dedicated Vue 3 component that wraps the core functionalities of Slickgrid-Universal, a TypeScript-written, framework-agnostic data grid library. It provides a comprehensive set of features, including various editors, filters, extensions, and services, enhancing the classic SlickGrid experience for modern Vue applications. The library is currently stable at version 10.5.0, with minor releases typically occurring every 2-4 weeks and major releases, such as v10.0.0, approximately annually. Key differentiators include its extensive suite of optional backend services (OData, GraphQL, and a newly introduced SQL Backend Service), robust export capabilities (Excel, PDF), and strong TypeScript support, making it suitable for complex enterprise-grade data visualization and manipulation within the Vue ecosystem. It aims to offer a highly configurable and performant data table solution, capable of handling large datasets efficiently.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'registerPlugin')
cause This error typically means a required SlickGrid plugin or an extension from Slickgrid-Universal was not properly imported, initialized, or provided in the grid options.fixVerify that all necessary plugins and extensions (e.g., `RowSelectionExtension`, `CellEditingExtension`) are imported and correctly included in `gridOptions.externalResources` or `gridOptions.plugins` as per the documentation. -
Failed to resolve component: slickgrid-vue
cause The `SlickgridVue` component was not correctly imported or registered within the Vue application or the parent component.fixEnsure `import { SlickgridVue } from 'slickgrid-vue';` is present in your component's script section (especially in `<script setup>`) and that Vue can resolve it. If using Options API, ensure it's listed in the `components` option. -
SyntaxError: Named export 'SlickgridVue' not found. The requested module 'slickgrid-vue' is a CommonJS module, which may not support all module.exports as named exports.
cause Attempting to use `require()` or incorrect named `import` syntax for a library primarily distributed as ES Modules in a modern Vue 3/TypeScript environment.fixUse ES Module `import` syntax: `import { SlickgridVue } from 'slickgrid-vue';`. Ensure your build tool (e.g., Vite) is configured for ESM. If encountering issues with `import type` for interfaces, ensure your TypeScript configuration and build process support it. -
Property 'id' is missing in type 'YourDataType' but required in type 'Column'.
cause A mismatch exists between the structure of your dataset objects and the expected type definitions for `Column` or other Slickgrid-Vue interfaces, often concerning the primary key `id` or `field` properties.fixEnsure your dataset objects (`User` in the quickstart) contain a unique `id` property (or specify `datasetIdPropertyName` in `GridOption` if using another key). Verify that `Column` definitions accurately reflect your data's fields and types, and use `import type` for clarity with interfaces. -
Cannot read properties of undefined (reading 'alwaysShowVerticalScroll')
cause This can occur when SlickGrid has difficulty calculating column widths, especially with CSS styles like `overflow-y: scroll` on the grid container, causing visual misalignments or rendering issues.fixIf experiencing column width problems or scrollbar collisions, try setting `gridOptions.alwaysShowVerticalScroll = true` to force the scrollbar to always be present, which can help with layout calculations.
Warnings
- breaking Version 10.0.0 introduced significant breaking changes. Projects upgrading from v9.x or earlier will require migration steps.
- deprecated The `optionItems` list within Menu Options has been deprecated and is scheduled for removal in v11.
- deprecated The `columnSort` property in ColumnPicker/GridMenu has been deprecated in favor of the more flexible `columnListBuilder`.
- gotcha CSS styling fixes and potential theme changes introduced in v10.3.0 may impact custom CSS overrides or existing themes.
- breaking Slickgrid-Vue (and its underlying Slickgrid-Universal) requires Vue.js version 3.5.0 or higher.
Install
-
npm install slickgrid-vue -
yarn add slickgrid-vue -
pnpm add slickgrid-vue
Imports
- SlickgridVue
const SlickgridVue = require('slickgrid-vue');import { SlickgridVue } from 'slickgrid-vue'; - Column, GridOption
import { Column, GridOption } from 'slickgrid-vue';import { type Column, type GridOption } from 'slickgrid-vue'; - Slickgrid-Vue Styles
import 'slickgrid-vue/dist/styles/css/slickgrid-theme-default.css';
Quickstart
<script setup lang="ts">
import { ref, type Ref } from 'vue';
import { type Column, type GridOption, SlickgridVue } from 'slickgrid-vue';
interface User {
id: number; // SlickGrid typically expects an 'id' field
firstName: string;
lastName: string;
age: number;
}
// It could also be `Column<User>[]`
const columns: Ref<Column<User>[]> = ref([
{ id: 'firstName', name: 'First Name', field: 'firstName', sortable: true, minWidth: 100 },
{ id: 'lastName', name: 'Last Name', field: 'lastName', sortable: true, minWidth: 100 },
{ id: 'age', name: 'Age', field: 'age', type: 'number', sortable: true, minWidth: 80 },
]);
const options = ref<GridOption>({
enableAutoResize: true,
enableColumnPicker: true,
enableGridMenu: true,
enablePagination: true,
pagination: { pageSizes: [10, 25, 50], pageSize: 10 },
enableFiltering: true,
enableSorting: true,
gridId: 'my-vue-grid',
datasetIdPropertyName: 'id' // Essential for data keying
});
const dataset = ref<User[]>([
{ id: 1, firstName: 'John', lastName: 'Doe', age: 20 },
{ id: 2, firstName: 'Jane', lastName: 'Smith', age: 21 },
{ id: 3, firstName: 'Peter', lastName: 'Jones', age: 35 },
{ id: 4, firstName: 'Alice', lastName: 'Williams', age: 28 },
{ id: 5, firstName: 'Robert', lastName: 'Brown', age: 42 },
]);
// Add a few more rows for better demonstration of pagination/scrolling
for (let i = 6; i <= 25; i++) {
dataset.value.push({
id: i,
firstName: `First${i}`,
lastName: `Last${i}`,
age: 20 + (i % 30)
});
}
</script>
<template>
<div class="my-grid-container" style="height: 500px; width: 100%;">
<slickgrid-vue
grid-id="grid1"
v-model:columns="columns"
v-model:dataset="dataset"
v-model:grid-options="options"
></slickgrid-vue>
</div>
</template>
<style>
@import 'slickgrid-vue/dist/styles/css/slickgrid-theme-default.css';
.my-grid-container {
border: 1px solid #ccc;
}
</style>