Skip to content

Commit

Permalink
Merge pull request #566 from revolist/parser-support
Browse files Browse the repository at this point in the history
feat: parser support for edit
  • Loading branch information
m2a2x authored Sep 13, 2024
2 parents 31f4227 + 4642b6a commit 52c8861
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/components/data/column.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DSourceState, getSourceItem, getVisibleSourceItem } from '@store';
import {
getCellData,
Observable,
CELL_CLASS,
DISABLED_CLASS,
getCellRaw,
getCellData,
} from '../../utils';
import { getRange } from '@store';

Expand Down Expand Up @@ -107,19 +107,14 @@ export default class ColumnService {
return model[prop] || '';
}

getCellData(r: number, c: number): string {
const data = this.rowDataModel(r, c);
return getCellData(data.model[data.prop as number]);
}

getSaveData(
rowIndex: number,
colIndex: number,
val?: string,
): BeforeSaveDataDetails {
const data = this.rowDataModel(rowIndex, colIndex);
if (typeof val === 'undefined') {
val = getCellData(data.model[data.prop as number]);
val = getCellData(data.value);
}
return {
prop: data.prop,
Expand Down
18 changes: 14 additions & 4 deletions src/components/overlay/revogr-overlay-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { isEditInput } from '../editors/edit.utils';
import { KeyboardService } from './keyboard.service';
import { AutoFillService } from './autofill.service';
import { verifyTouchTarget } from '../../utils/events';
import { getCellData } from '../../utils';
import {
Observable,
SelectionStoreState,
Expand Down Expand Up @@ -492,11 +493,18 @@ export class OverlaySelection {
if (this.readonly || !editCell) {
return null;
}
const val =
editCell.val || this.columnService.getCellData(editCell.y, editCell.x);
const enteredOrModelValue =
editCell.val ||
getCellData(
this.columnService.rowDataModel(editCell.y, editCell.x).value
);
const editable = {
...editCell,
...this.columnService.getSaveData(editCell.y, editCell.x, val),
...this.columnService.getSaveData(
editCell.y,
editCell.x,
enteredOrModelValue,
),
};
const renderEvent = this.beforeEditRender.emit({
range: {
Expand Down Expand Up @@ -860,7 +868,9 @@ export class OverlaySelection {
}

private rowDragStart({ detail }: CustomEvent<{ cell: Cell; text: string }>) {
detail.text = this.columnService.getCellData(detail.cell.y, detail.cell.x);
detail.text = getCellData(
this.columnService.rowDataModel(detail.cell.y, detail.cell.x).value
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/serve/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export function generateFakeDataObject(config = {}) {
prop: rgCol,
sortable: true,
size: 100,
// custom sorting
cellCompare: rgCol % 2 == 0 ? naturalSort : undefined,
// custom sorting except of 0 row
cellCompare: !!rgCol && rgCol % 2 == 0 ? naturalSort : undefined,
cellProperties: ({ colIndex }) => ({
className: {
'first-column': colIndex === 0,
Expand Down Expand Up @@ -115,6 +115,7 @@ export function generateFakeDataObject(config = {}) {
'custom-row-index': rowIndex
};
}
columns[rgCol].cellParser = () => 'a';
columns[rgCol].cellTemplate = (h, { value }) => {
// // delay
// // for(let i = 0; i < 10000000; i++) {
Expand Down

0 comments on commit 52c8861

Please sign in to comment.