Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added capability to configure a double click event on rows #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/DynamicDataGrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
<caption>On click action</caption>
<description />
</property>
<property key="onDoubleClickRow" type="action" required="false" dataSource="dataSourceRow">
<caption>On double click action</caption>
<description />
</property>
</propertyGroup>
<propertyGroup caption="Column header">
<property key="onClickColumnHeader" type="action" required="false" dataSource="dataSourceColumn">
Expand Down
2 changes: 1 addition & 1 deletion src/components/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface CellProps {
children: ReactNode;
className?: string;
key: string;
onClick?: () => void;
onClick?: (event?: React.MouseEvent) => void;
rowIndex: number;
renderAs: RenderAsEnum;
}
Expand Down
15 changes: 9 additions & 6 deletions src/components/Cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function Cells(props: CellsProps): ReactElement {
const { dataSourceCell, referenceRow, referenceColumn, dataSourceColumn, renderAs, pageCell } = props;
const { showRowAs, columnClass, cellClass } = props;
const { row, rowIndex, loading } = props;
const { onClickRow, onClickCell, onClickColumn, onClickRowHeader } = props;
const { onClickRow, onDoubleClickRow, onClickCell, onClickColumn, onClickRowHeader } = props;
// potential optimize with hash table?
const cells =
dataSourceColumn.items?.map(column => {
Expand All @@ -68,14 +68,17 @@ Please make sure your cell sort order and row sort order are matching, and cell
);
}

const onClick =
const onClick = (e: React.MouseEvent) =>
cell && onClickCell
? (): void => onClickCell?.get(cell).execute()
: onClickRow
? (): void => onClickRow?.get(row).execute()
? onClickCell?.get(cell).execute()
: onClickRow && e.detail === 1
? onClickRow?.get(row).execute()
: onDoubleClickRow && e.detail === 2
? onDoubleClickRow?.get(row).execute()
: onClickColumn
? (): void => onClickColumn?.get(column).execute()
? onClickColumn?.get(column).execute()
: undefined;

const cellClassColumn = columnClass?.get(column).value ?? undefined;
const cellClassValue = (cell && cellClass?.get(cell).value) ?? undefined;
return (
Expand Down
2 changes: 2 additions & 0 deletions typings/DynamicDataGridProps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface DynamicDataGridContainerProps {
columnClass?: ListExpressionValue<string>;
onClickRowHeader?: ListActionValue;
onClickRow?: ListActionValue;
onDoubleClickRow?: ListActionValue;
onClickColumnHeader?: ListActionValue;
onClickColumn?: ListActionValue;
onClickCell?: ListActionValue;
Expand Down Expand Up @@ -99,6 +100,7 @@ export interface DynamicDataGridPreviewProps {
columnClass: string;
onClickRowHeader: {} | null;
onClickRow: {} | null;
onDoubleClickRow: {} | null;
onClickColumnHeader: {} | null;
onClickColumn: {} | null;
onClickCell: {} | null;
Expand Down