Skip to content

Commit

Permalink
Refactor #2368
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 1, 2021
1 parent da3ed51 commit 35e8b2f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
26 changes: 24 additions & 2 deletions src/components/column/Column.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';

type ColumnBodyType = React.ReactNode | ((data: any, props: ColumnProps, ...parameters: any) => React.ReactNode);
type ColumnBodyType = React.ReactNode | ((data: any, options: ColumnBodyOptions) => React.ReactNode);

type ColumnEditorType = React.ReactNode | ((options: ColumnEditorOptions) => React.ReactNode);

type ColumnFilterMatchModeType = 'startsWith' | 'contains' | 'endsWith' | 'equals' | 'notEquals' | 'in' | 'lt' | 'lte' | 'gt' | 'gte' | 'custom';

Expand All @@ -26,6 +28,26 @@ type ColumnFilterElementType = React.ReactNode | ((options: ColumnFilterElementT

type ColumnFilterModelType = ColumnFilterMetaData | ColumnFilterMetaDataWithConstraint;

interface ColumnBodyOptions {
column: Column;
field: string;
rowIndex: number;
frozenRow?: boolean;
props: any;
}

interface ColumnEditorOptions {
node?: any;
rowData: any;
value: any;
column: Column;
field: string;
rowIndex: number;
frozenRow?: boolean;
props: any;
editorCallback?(val: any): void;
}

interface ColumnFilterModelOptions {
[key: string]: ColumnFilterModelType;
}
Expand Down Expand Up @@ -183,7 +205,7 @@ export interface ColumnProps {
onCellEditCancel?(e: ColumnEventParams): void;
sortFunction?(e: ColumnSortParams): void;
filterFunction?(value: any, filter: any, filterLocale: string, params: ColumnFilterParams): void;
editor?(props: ColumnProps): React.ReactNode;
editor?: ColumnEditorType;
cellEditValidator?(e: ColumnEventParams): boolean;
onBeforeCellEditHide?(e: ColumnEventParams): void;
onBeforeCellEditShow?(e: ColumnEventParams): void;
Expand Down
10 changes: 5 additions & 5 deletions src/components/datatable/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,15 @@ export class BodyCell extends Component {
}

onRowEditInit(event) {
this.props.onRowEditInit({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex, editorCallback: this.editorCallback });
this.props.onRowEditInit({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex });
}

onRowEditSave(event) {
this.props.onRowEditSave({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex, editorCallback: this.editorCallback });
this.props.onRowEditSave({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex });
}

onRowEditCancel(event) {
this.props.onRowEditCancel({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex, editorCallback: this.editorCallback });
this.props.onRowEditCancel({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex });
}

bindDocumentEditListener() {
Expand Down Expand Up @@ -517,10 +517,10 @@ export class BodyCell extends Component {
const title = this.props.responsiveLayout === 'stack' && <span className="p-column-title">{ObjectUtils.getJSXElement(header, { props: this.props })}</span>;

if (body && !this.state.editing) {
content = body ? ObjectUtils.getJSXElement(body, this.props.rowData, { column: this.props.column, field: this.field, rowIndex: this.props.rowIndex, frozenRow: this.props.frozenRow }) : value;
content = body ? ObjectUtils.getJSXElement(body, this.props.rowData, { column: this.props.column, field: this.field, rowIndex: this.props.rowIndex, frozenRow: this.props.frozenRow, props: this.props.tableProps }) : value;
}
else if (editor && this.state.editing) {
content = ObjectUtils.getJSXElement(editor, { rowData: this.state.editingRowData, value: this.resolveFieldData(this.state.editingRowData), column: this.props.column, field: this.field, rowIndex: this.props.rowIndex, frozenRow: this.props.frozenRow, editorCallback: this.editorCallback });
content = ObjectUtils.getJSXElement(editor, { rowData: this.state.editingRowData, value: this.resolveFieldData(this.state.editingRowData), column: this.props.column, field: this.field, rowIndex: this.props.rowIndex, frozenRow: this.props.frozenRow, props: this.props.tableProps, editorCallback: this.editorCallback });
}
else if (selectionMode) {
const showSelection = this.props.showSelectionElement ? this.props.showSelectionElement(this.props.rowData, { index: this.props.rowIndex, props: this.props.tableProps }) : true;
Expand Down
4 changes: 3 additions & 1 deletion src/components/datatable/DataTable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type DataTableFilterDisplayType = 'menu' | 'row';

type DataTableSizeType = 'small' | 'normal' | 'large';

type DataTableScrollDirectionType = 'vertical' | 'horizontal' | 'both';

interface DataTableHeaderTemplateOptions {
props: DataTableProps;
}
Expand Down Expand Up @@ -156,7 +158,6 @@ interface DataTableRowEditCompleteParams extends DataTableRowEventParams {
newData: any;
field: string;
index: number;
editorCallback(value: any): void;
}

interface DataTableSelectParams {
Expand Down Expand Up @@ -265,6 +266,7 @@ export interface DataTableProps {
filterLocale?: string;
scrollable?: boolean;
scrollHeight?: string;
scrollDirection?: DataTableScrollDirectionType;
virtualScrollerOptions?: VirtualScrollerProps;
frozenWidth?: string;
frozenValue?: any[];
Expand Down
2 changes: 2 additions & 0 deletions src/components/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class DataTable extends Component {
filterLocale: undefined,
scrollable: false,
scrollHeight: null,
scrollDirection: 'vertical',
virtualScrollerOptions: null,
frozenWidth: null,
frozenValue: null,
Expand Down Expand Up @@ -188,6 +189,7 @@ export class DataTable extends Component {
filterLocale: PropTypes.string,
scrollable: PropTypes.bool,
scrollHeight: PropTypes.string,
scrollDirection: PropTypes.string,
virtualScrollerOptions: PropTypes.object,
frozenWidth: PropTypes.string,
frozenValue: PropTypes.array,
Expand Down

0 comments on commit 35e8b2f

Please sign in to comment.