Skip to content

Commit d52cb42

Browse files
committed
fix: upgrade filter icon after update plugin options
1 parent 1e6dfe2 commit d52cb42

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

packages/vtable-plugins/demo/filter/filter.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,26 @@ export function createTable() {
439439
// }, 2000);
440440

441441
// 插件更新
442-
// setTimeout(() => {
443-
// console.log('update');
444-
// tableInstance.updateOption({
445-
// ...option,
446-
// plugins: [filterPlugin]
447-
// });
448-
// }, 8000);
442+
setTimeout(() => {
443+
console.log('update');
444+
// tableInstance.updateOption({
445+
// ...option,
446+
// plugins: [filterPlugin]
447+
// });
448+
filterPlugin.updatePluginOptions({
449+
...getTableFilterPluginAttrFromProps(),
450+
filterIcon: {
451+
name: 'filter-icon',
452+
type: 'svg',
453+
width: 120,
454+
height: 120,
455+
positionType: VTable.TYPES.IconPosition.right,
456+
cursor: 'pointer',
457+
marginRight: 4,
458+
svg: `<svg t="1752821809070" class="icon" viewBox="0 0 1664 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="12092" width="200" height="200" transform="translate(0,30)"><path d="M89.6 179.2A89.6 89.6 0 0 1 89.6 0h1408a89.6 89.6 0 0 1 0 179.2H89.6z m256 384a89.6 89.6 0 0 1 0-179.2h896a89.6 89.6 0 0 1 0 179.2h-896z m256 384a89.6 89.6 0 0 1 0-179.2h384a89.6 89.6 0 0 1 0 179.2h-384z" fill="red" p-id="12093"></path></svg>`
459+
}
460+
});
461+
}, 5000);
449462

450463
// 实例释放
451464
// setTimeout(() => {
@@ -464,4 +477,20 @@ export function createTable() {
464477
args[0].event.preventDefault();
465478
console.log('icon_click');
466479
});
480+
481+
const HEADER_FILTER_HIGHLIGHT = 'header_filter_highlight';
482+
const HEADER_FILTER_DEFAULT = 'header_filter_default';
483+
tableInstance.registerCustomCellStyle(HEADER_FILTER_HIGHLIGHT, {
484+
bgColor: 'red'
485+
});
486+
tableInstance.registerCustomCellStyle(HEADER_FILTER_DEFAULT, {
487+
bgColor: 'blue'
488+
});
489+
490+
tableInstance.on('filter_menu_show', ({ col, row }) => {
491+
tableInstance.arrangeCustomCellStyle({ col, row }, HEADER_FILTER_HIGHLIGHT);
492+
});
493+
tableInstance.on('filter_menu_hide', ({ col, row }) => {
494+
tableInstance.arrangeCustomCellStyle({ col, row }, HEADER_FILTER_DEFAULT);
495+
});
467496
}

packages/vtable-plugins/src/filter/filter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class FilterPlugin implements pluginsDefinition.IVTablePlugin {
153153
this.pluginOptions = merge(this.pluginOptions, pluginOptions);
154154
// 更新筛选器UI样式
155155
this.filterToolbar.updateStyles(this.pluginOptions.styles);
156+
// 更新icon
157+
(this.table as ListTable).updateColumns(this.columns, {
158+
clearRowHeightCache: false
159+
});
156160
}
157161

158162
// 当用户的配置项更新时调用
@@ -236,6 +240,8 @@ export class FilterPlugin implements pluginsDefinition.IVTablePlugin {
236240
const filterIcon = this.pluginOptions.filterIcon;
237241
const filteringIcon = this.pluginOptions.filteringIcon;
238242

243+
// console.log('filterIcon', filterIcon);
244+
239245
const isIconEqual = (a: any, b: any) =>
240246
a === b || (a && b && typeof a === 'object' && typeof b === 'object' && a.name === b.name);
241247

0 commit comments

Comments
 (0)