Filter Slider
Source code
import { defineCustomElements } from '@revolist/revogrid/loader';import { AdvanceFilterPlugin, ColumnStretchPlugin } from '@revolist/revogrid-pro';defineCustomElements();
import { currentTheme, useRandomData } from '../composables/useRandomData';
const { createRandomData } = useRandomData();const { isDark } = currentTheme();export function load(parentSelector: string) { const grid = document.createElement('revo-grid');
grid.source = createRandomData(100); grid.columns = [ { name: '๐ ID', prop: 'id', filter: ['number', 'slider'] }, { name: '๐ Fruit', prop: 'name', }, ]; // Define plugin grid.plugins = [AdvanceFilterPlugin, ColumnStretchPlugin];
grid.additionalData = { stretch: 'all' }; grid.filter = {}; grid.theme = isDark() ? 'darkCompact' : 'compact'; grid.hideAttribution = true; document.querySelector(parentSelector)?.appendChild(grid);}
<template> <VGrid class="cell-border" :theme="isDark ? 'darkMaterial' : 'material'" :columns="columns" :source="rows" :plugins="plugins" :additionalData="additionalData" :filter="filter" hide-attribution /></template>
<script setup lang="ts">import { ref } from 'vue'import { currentThemeVue } from '../composables/useRandomData'import { VGrid } from '@revolist/vue3-datagrid'import { AdvanceFilterPlugin, ColumnStretchPlugin, RowOddPlugin, RowSelectPlugin } from '@revolist/revogrid-pro'
const { isDark } = currentThemeVue();import { faker } from '@faker-js/faker'const columns = ref([ { name: 'Size', prop: 'size', rowSelect: true, filter: ['number', 'slider'] },])
const plugins = ref([AdvanceFilterPlugin, ColumnStretchPlugin, RowOddPlugin, RowSelectPlugin])
const rows = ref(Array.from({ length: 1000 }, (_, i) => ({ size: faker.number.float({ min: 0, max: 1000 }),})))
const additionalData = ref({ stretch: 'all',})
const filter = ref({})</script>
import { useState, useMemo, useRef } from 'react';import { RevoGrid, type DataType } from '@revolist/react-datagrid';import { AdvanceFilterPlugin, ColumnStretchPlugin,} from '@revolist/revogrid-pro';import { useRandomData, currentTheme } from '../composables/useRandomData';
function FilterAdvanced() { const { isDark } = currentTheme(); const { createRandomData } = useRandomData(); const gridRef = useRef<HTMLRevoGridElement>(null); const [source] = useState<DataType[]>(createRandomData(100));
const columns = useMemo( () => [ { name: '๐ ID', prop: 'id', filter: ['number', 'slider'], }, { name: '๐ Fruit', prop: 'name', }, ], [] );
const additionalData = useMemo( () => ({ stretch: 'all', filter: {}, }), [] );
return ( <RevoGrid ref={gridRef} columns={columns} source={source} additionalData={additionalData} hide-attribution theme={isDark() ? 'darkCompact' : 'compact'} plugins={[AdvanceFilterPlugin, ColumnStretchPlugin]} /> );}
export default FilterAdvanced;
import { Component, ViewEncapsulation } from '@angular/core';import { RevoGrid } from '@revolist/angular-datagrid';import { AdvanceFilterPlugin, ColumnStretchPlugin } from '@revolist/revogrid-pro';import { currentTheme, useRandomData } from '../composables/useRandomData';
@Component({ selector: 'filter-advanced-angular', standalone: true, imports: [RevoGrid], template: ` <revo-grid [columns]="columns" [source]="source" [additionalData]="additionalData" [filter]="filter" [hideAttribution]="true" [theme]="theme" [plugins]="plugins" style="height: 400px;" ></revo-grid>`, encapsulation: ViewEncapsulation.None,})export class FilterAdvancedGridComponent { theme = currentTheme().isDark() ? 'darkCompact' : 'compact'; source = useRandomData().createRandomData(100);
columns = [ { name: '๐ ID', prop: 'id', filter: ['number', 'slider'], }, { name: '๐ Fruit', prop: 'name', }, ];
additionalData = { stretch: 'all', };
filter = {}; plugins = [AdvanceFilterPlugin, ColumnStretchPlugin];}
The Advanced Filtering Plugin for RevoGrid extends the gridโs capabilities by introducing powerful filtering options, making data management more efficient and flexible. This plugin includes new filter types, such as slider and selection, which provide intuitive ways for users to interact with and refine data views.
Key Features
- Custom Filter Types: Enables the use of slider and selection filters, allowing users to quickly narrow down data based on specific criteria.
- Flexible and Extensible: This plugin demonstrates the potential for creating custom plugins, encouraging developers to expand the gridโs functionality further.
- Automatic Theme Support: The plugin adapts to light or dark themes based on user settings.
Usage Example
import { AdvanceFilterPlugin } from '@revolist/revogrid-pro';
// Basic setupconst grid = document.createElement('revo-grid');grid.columns = [ { name: 'Numeric Column', prop: 'numericValue', filter: ['number', 'slider'] }];grid.plugins = [AdvanceFilterPlugin];grid.filter = {};
// Advanced setup with slider configurationgrid.filter = { slider: { showTooltips: true, showRangeDisplay: true, formatValue: (value) => `$${value.toFixed(2)}` }};
Slider Configuration Options
The slider filter can be customized using the following configuration options:
Option | Type | Default | Description |
---|---|---|---|
showTooltips | boolean | true | Shows tooltips when hovering over the slider handles |
showRangeDisplay | boolean | true | Displays the current range values above the slider |
formatValue | function | (value) => value.toFixed(2) | Custom function to format the displayed values |
Styling
The slider component supports custom styling through CSS variables:
revo-grid { --slider-color: #c6c6c6; /* Color of the inactive slider track */ --range-color: #0068f0; /* Color of the active slider range */ --tooltip-bg: #333333; /* Tooltip background color */ --tooltip-color: #ffffff; /* Tooltip text color */}
/* Dark theme support */revo-grid[theme^='dark'] { --slider-color: #c6c6c6; --range-color: #0068f0; --filter-input-bg: #333333; --filter-input-color: #ffffff; --tooltip-bg: #f2f2f6; --tooltip-color: #333333;}
Advanced Features
-
Range Selection:
- The slider provides two handles for selecting a range of values
- Values are automatically normalized between the minimum and maximum values in your dataset
- Real-time filtering as users adjust the range
-
Tooltips:
- Interactive tooltips show the exact value when hovering over slider handles
- Tooltips can be customized using the
formatValue
function - Position updates dynamically as the handles move
-
Range Display:
- Optional display of current range values above the slider
- Formatted values using the same
formatValue
function - Clear visual feedback of the selected range
-
Theme Integration:
- Automatically adapts to light and dark themes
- Customizable colors through CSS variables
- Consistent look and feel with the rest of your grid
Integration with Other Filters
The slider filter can be combined with other filter types for more complex filtering scenarios:
grid.columns = [ { name: 'Price', prop: 'price', filter: ['number', 'slider', 'selection'] // Combine with selection filter }];
Best Practices
-
Performance:
- The slider filter is optimized for large datasets
- Range calculations are performed efficiently
- Real-time updates are throttled for smooth performance
-
User Experience:
- Use
showTooltips
for precise value selection - Implement
formatValue
for meaningful value display - Enable
showRangeDisplay
for clear range visualization
- Use
-
Accessibility:
- Slider handles are keyboard-navigable
- ARIA attributes are automatically applied
- High contrast visual feedback for active states
Customization and Extensibility
This plugin highlights the extensibility of RevoGridโs plugin system, showcasing how developers can build and integrate advanced features tailored to specific needs. The flexibility of RevoGrid plugins enables comprehensive data manipulation and display control, making it an ideal choice for complex data-driven applications. For a deeper dive into plugin development, refer to the RevoGrid Plugin Documentation.