VueJS cellEditEnded 및 formatitem의 class를 추가시 문제
페이지 정보
작성자 liilililil 작성일 2023-10-11 12:00 조회 291회 댓글 1건본문
관련링크
안녕하세요.
특정 상황에 따른 cell의 class 추가시 문제가 발생하여 문의드립니다.
1.http://demo.grapecity.co.kr/wijmo/learn-wijmo/Grid/Editing/HighlightEdits/vue
해당 데모에서 아래와 같이 코드를 수정하였을때,
celllEditEnded 시점에 class를 추가합니다.
그러나, 타 행의 cell을 클릭하면 추가한 class가 사라지는 현상이 발생합니다.
( 동일 행은 유지 되고 있습니다.)
class를 유지시키려면 어떻게 해야 하나요?
import { isUndefined, isDate, toggleClass, addClass} from '@grapecity/wijmo'; /** * Class that highlights cells that have been edited in a FlexGrid. */ export class EditHighlighter { /** * Initializes a new instance of the {@link EditHighlighter} class. * * @param grid FlexGrid to highlight. * @param cssClass Class name to apply to changed cells. */ constructor(grid, cssClass) { this._originalValue = null; this._originalValues = new Map(); this._grid = grid; let cellChanging = this._cellChanging.bind(this), cellChanged = this._cellChanged.bind(this); grid.beginningEdit.addHandler(cellChanging); grid.cellEditEnded.addHandler(cellChanged); grid.pastingCell.addHandler(cellChanging); grid.pastedCell.addHandler(cellChanged); // grid.formatItem.addHandler((s, e) => { // if (e.panel == s.cells) { // let changed = this._hasChange(e.getRow().dataItem, e.getColumn().binding); // toggleClass(e.cell, 'cell-changed', changed); // } // }); } /** * Clears all the changes and removes all highlights. */ clearChanges() { this._originalValues.clear(); this._grid.invalidate(); } // checks whether a cell has changed _hasChange(item, binding) { item = this._originalValues.get(item); return item != null && !isUndefined(item[binding]); } // handles cell changing (edit or paste) _cellChanging(s, e) { this._originalValue = s.getCellData(e.row, e.col, false); } // handles cell changed (edit or paste) _cellChanged(s, e) { let newValue = s.getCellData(e.row, e.col, false); this._storeChange(e.getRow().dataItem, e.getColumn().binding, this._originalValue, newValue); const cellElement = e.panel.getCellElement(e.row, e.col); addClass(cellElement, 'cell-changed'); } // store a change into the _originalValues map _storeChange(item, binding, originalValue, newValue) { // get the item with the original values let editItem = this._originalValues.get(item); if (editItem == null) { editItem = {}; this._originalValues.set(item, editItem); } // get the original value from the item if possible let editValue = editItem[binding]; if (!isUndefined(editValue)) { originalValue = editValue; } // store or clear the change if (this._sameValue(originalValue, newValue)) { delete editItem[binding]; if (Object.keys(editItem).length == 0) { this._originalValues.delete(item); } } else { editItem[binding] = originalValue; } } // compare two values taking dates into account _sameValue(item1, item2) { if (item1 === item2) { return true; } if (isDate(item1) && isDate(item2)) { return item1.getTime() == item2.getTime(); } return false; } }