编辑
以下作品,我对其进行了测试。我还添加了代码以保持最后一个事件名称被触发(onClose/onOpen),这样您在打开选择下拉菜单时就不会触发 editCommandHandler。您还应该使用最新版本的 Angular-Slickgrid 版本2.25.0
,所有编辑器/过滤器现在都是公共的,因此更容易扩展它们(请参阅最新版本说明)。
export class CustomSelectEditor extends SingleSelectEditor {
private lastEventName = '';
constructor(args) {
super(args);
// retrieve the options that were provided to multipleSelect.JS
// we will override the onClose/onOpen to get last event name triggered
// Note: make sure that the onClose is still calling the this.save() else nothing will work
const libOptions = this.editorDomElement.multipleSelect('getOptions');
libOptions.onClose = () => {
this.lastEventName = 'onClose';
this.save();
};
libOptions.onOpen = () => {
this.lastEventName = 'onOpen';
}
this.editorDomElement.multipleSelect('refreshOptions', libOptions);
}
isValueChanged(): boolean {
// return true only when it's the onClose event to fire the editCommandHandler
if (this.lastEventName === 'onClose') {
return true;
}
// but keep previous logic when it's not the onClose event
if (this.isMultipleSelect) {
return !charArraysEqual(this.$editorElm.val(), this.originalValue);
}
return this.$editorElm.val() !== this.originalValue;
}
}
所有编辑器的编写方式都是为了避免在没有任何更改时触发事件,如果您真的希望更改该行为,那么您可以扩展SelectEditor
并覆盖isValueChanged()函数。
请注意,我没有测试下面的代码,但它应该可以工作,我不确定是否SelectEditor
实际上是公开的,如果不是,则尝试扩展Editors.singleSelect
和Editors.multipleSelect
首先尝试SelectEditor
直接扩展(我认为它们目前不是公开的,这不起作用,但我可能会在未来的版本中改变它)
import { SelectEditor } from 'angular-slickgrid';
export class CustomSelectEditor extends SelectEditor {
constructor() {
super();
}
isValueChanged(): boolean {
// your custom logic
}
}
或者Editors.singleSelect
如果SelectEditor
不公开
import { Editors } from 'angular-slickgrid';
export class CustomSelectEditor extends Editors.inputText {
constructor() {
super();
}
isValueChanged(): boolean {
// your custom logic
}
}
然后在列定义的自定义编辑器中使用它
{
id: 'status', name: 'Status', field: 'status',
filterable: true,
editor: {
collection: [{ value: 'progress', label: 'Progress' }, { value: 'new', label: 'New' }, { value: 'done', label: 'Done' }],
model: CustomSelectEditor
}
}