Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3a0e493
refactor: migrate event controllers from DI to React Context for simp…
iobuhov Nov 20, 2025
5f1e82b
refactor: migrate event handlers to container
iobuhov Nov 20, 2025
256657e
refactor: extract drag & drop state and logic to mobx
yordan-st Nov 20, 2025
7a0adc9
refactor: update components to use new state management
yordan-st Nov 20, 2025
669b31d
refactor: remove obsolete tests and snapshots, create for new component
yordan-st Nov 20, 2025
84067dd
refactor: rewrite columnreszier to use injection hooks
yordan-st Nov 20, 2025
6d8f751
refactor: enhance ColumnResizer test structure and update snapshot
yordan-st Nov 20, 2025
3a0b07c
refactor: fix failing test
yordan-st Nov 21, 2025
ba0db64
feat: enhance drag-and-drop functionality with DragHandle component
yordan-st Nov 21, 2025
d1b05ff
refactor: fix lint errors
yordan-st Nov 21, 2025
267c51e
refactor: standardize use of brandi
yordan-st Nov 27, 2025
6d3a21a
refactor: improve naming, consistency and clean up
yordan-st Nov 28, 2025
b4ccf26
refactor: ensure consistent naming, prop destructuring, update tests
yordan-st Dec 1, 2025
bc7504c
fix: update SelectActionHandler initialization to use null instead of…
yordan-st Dec 2, 2025
e45deee
fix: restore sort icon state, add dragndropdesign mode and react icon
yordan-st Dec 8, 2025
2604511
chore: update unit test snapshot
yordan-st Dec 9, 2025
b17a4b7
fix: restore individual column reorder and reflect in preview, revert…
yordan-st Dec 11, 2025
950ea89
test: update e2e screenshots baseline
leonardomendix Dec 12, 2025
b41f336
feat: enhance drag-and-drop functionality with new drag handle and st…
yordan-st Dec 18, 2025
15032e0
chore: remove unused dnd-kit dependencies and update mobx-react-lite …
yordan-st Dec 23, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,16 @@ $root: ".widget-datagrid";
background-color: var(--bg-color-secondary, $bg-color-secondary);
border-width: 0;
border-color: var(--grid-border-color, $grid-border-color);
padding: var(--spacing-medium, $spacing-medium);
padding: 0 var(--spacing-medium, $spacing-medium);
top: 0;
min-width: 0;
position: relative;
}
}

.th {
&.dragging {
opacity: 0.5;
&.dragging-over-self {
opacity: 0.8;
}
}

&.drop-after:after,
&.drop-before:after {
content: "";
position: absolute;
top: 0;
height: 100%;
width: var(--spacing-smaller, $spacing-smaller);
background-color: $dragging-color-effect;

z-index: 1;
}

&.drop-before {
&:after {
left: 0;
}
&:not(:first-child):after {
transform: translateX(-50%);
}
}

&.drop-after {
&:after {
right: 0;
}
&:not(:last-child):after {
transform: translateX(50%);
}
&.dragging-over-self {
opacity: 0.8;
}

/* Clickable column header (Sortable) */
Expand Down Expand Up @@ -92,13 +59,84 @@ $root: ".widget-datagrid";
}
}

/* Drag handle */
.drag-handle {
cursor: grab;
pointer-events: auto;
position: relative;
padding: 12px 4px 4px 4px;
flex-grow: 0;
flex-shrink: 0;
display: flex;
justify-content: center;
align-self: flex-start;
z-index: 1;
opacity: 0;
transition: opacity 0.15s ease;

&:hover {
svg {
color: var(--brand-primary, $brand-primary);
}
}
&:active {
cursor: grabbing;
}
&:focus-visible {
opacity: 1;
}
svg {
margin: 0;
width: 8px;
}
}

&.locked-drag-active {
z-index: 2;
}

&.dragging-over-self {
opacity: 0.25;
}

&:hover .drag-handle,
&:focus-within .drag-handle {
opacity: 1;
}

/* Parent background change on drag handle hover */
&:has(.drag-handle:hover) {
background-color: var(--brand-primary-50, $brand-light);
}

/* Drag preview (dnd-kit) should look like hovered header */
&.drag-preview {
background-color: var(--brand-primary-50, $brand-light);
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
border: 1px solid var(--gray-light, $gray-light);

.drag-handle {
opacity: 1;

svg {
color: var(--brand-primary, $brand-primary);
}
}
}

/* Remove left padding when drag handle is present */
&:has(.drag-handle) {
padding-left: 0;
}

/* Content of the column header */
.column-container {
display: flex;
flex-direction: column;
flex-grow: 1;
align-self: stretch;
min-width: 0;
padding: var(--spacing-small, $spacing-small) 0;

&:not(:has(.filter)) {
.column-header {
Expand Down Expand Up @@ -143,7 +181,9 @@ $root: ".widget-datagrid";
/* Header filter */
.filter {
display: flex;
margin-top: 4px;
> * {
margin-top: 4px;
}
> .form-group {
margin-bottom: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $brand-light: #e6eaff !default;
$grid-selected-row-background: $brand-light !default;

// Text and icon colors
$gray-light: #6c7180 !default;
$gray-dark: #606671 !default;
$gray-darker: #3b4251 !default;
$pagination-caption-color: #0a1325 !default;
Expand All @@ -33,7 +34,7 @@ $spacing-larger: 32px !default;
$gallery-gap: $spacing-small !default;

// Effects and animations
$dragging-color-effect: rgba(10, 19, 37, 0.8) !default;
$dragging-color-effect: $brand-primary !default;
$skeleton-background: linear-gradient(90deg, rgba(194, 194, 194, 0.2) 0%, #d2d2d2 100%) !default;

// Assets
Expand Down
28 changes: 12 additions & 16 deletions packages/pluggableWidgets/datagrid-web/e2e/DataGrid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,23 @@ test.describe("capabilities: sorting", () => {
await page.goto("/");
await page.waitForLoadState("networkidle");
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1)).toHaveText("First Name");
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg")).toHaveAttribute(
"data-icon",
"arrows-alt-v"
);
await expect(
page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg[data-icon='arrows-alt-v']")
).toBeVisible();
await expect(page.getByRole("gridcell", { name: "12" }).first()).toHaveText("12");
});

test("changes order of data to ASC when clicking sort option", async ({ page }) => {
await page.goto("/");
await page.waitForLoadState("networkidle");
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1)).toHaveText("First Name");
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg")).toHaveAttribute(
"data-icon",
"arrows-alt-v"
);
await expect(
page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg[data-icon='arrows-alt-v']")
).toBeVisible();
await page.locator(".mx-name-datagrid1 .column-header").nth(1).click();
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg")).toHaveAttribute(
"data-icon",
"long-arrow-alt-up"
);
await expect(
page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg[data-icon='long-arrow-alt-up']")
).toBeVisible();
await expect(page.getByRole("gridcell", { name: "10" }).first()).toHaveText("10");
});

Expand All @@ -78,10 +75,9 @@ test.describe("capabilities: sorting", () => {
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1)).toHaveText("First Name");
await page.locator(".mx-name-datagrid1 .column-header").nth(1).click();
await page.locator(".mx-name-datagrid1 .column-header").nth(1).click();
await expect(page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg")).toHaveAttribute(
"data-icon",
"long-arrow-alt-down"
);
await expect(
page.locator(".mx-name-datagrid1 .column-header").nth(1).locator("svg[data-icon='long-arrow-alt-down']")
).toBeVisible();
await expect(page.getByRole("gridcell", { name: "12" }).first()).toHaveText("12");
});
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/pluggableWidgets/datagrid-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"verify": "rui-verify-package-format"
},
"dependencies": {
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@floating-ui/react": "^0.26.27",
"@mendix/widget-plugin-component-kit": "workspace:*",
"@mendix/widget-plugin-external-events": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ColumnsPreviewType, DatagridPreviewProps } from "typings/DatagridProps"
import { FaArrowsAltV } from "./components/icons/FaArrowsAltV";
import { FaEye } from "./components/icons/FaEye";
import { ColumnPreview } from "./helpers/ColumnPreview";

import "./ui/DatagridPreview.scss";

declare module "mendix/preview/Selectable" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import classNames from "classnames";
import { ReactElement } from "react";
import { ColumnHeader } from "./ColumnHeader";
import { useColumn, useColumnsStore, useDatagridConfig, useHeaderDndVM } from "../model/hooks/injection-hooks";
import { ColumnResizerProps } from "./ColumnResizer";
import { observer } from "mobx-react-lite";
import { DragHandle } from "./DragHandle";
import { useSortable } from "@dnd-kit/sortable";

export interface ColumnContainerProps {
isLast?: boolean;
resizer: ReactElement<ColumnResizerProps>;
}

export const ColumnContainer = observer(function ColumnContainer(props: ColumnContainerProps): ReactElement {
const { columnsFilterable, columnsDraggable, id: gridId } = useDatagridConfig();
const columnsStore = useColumnsStore();
const { columnFilters } = columnsStore;
const column = useColumn();
const { canSort, columnId, columnIndex, canResize, sortDir, header } = column;
const caption = header.trim();
const vm = useHeaderDndVM();
const isDndEnabled = Boolean(columnsDraggable && column.canDrag);
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
id: columnId,
disabled: !isDndEnabled
});
const setHeaderRef = (ref: HTMLDivElement | null): void => {
column.setHeaderElementRef(ref);
setNodeRef(ref);
};
const style = vm.getHeaderCellStyle(columnId, { transform, transition });
const isLocked = !column.canDrag;

return (
<div
aria-sort={getAriaSort(canSort, sortDir)}
className={classNames("th", {
"dragging-over-self": isDragging,
"locked-drag-active": isLocked && vm.isDragging
})}
role="columnheader"
style={style}
title={caption}
ref={setHeaderRef}
data-column-id={columnId}
>
{isDndEnabled && (
<DragHandle setActivatorNodeRef={setActivatorNodeRef} listeners={listeners} attributes={attributes} />
)}
<div className={classNames("column-container")} id={`${gridId}-column${columnId}`}>
<ColumnHeader />
{columnsFilterable && (
<div className="filter" style={{ pointerEvents: vm.isDragging ? "none" : undefined }}>
{columnFilters[columnIndex]?.renderFilterWidgets()}
</div>
)}
</div>
{canResize ? props.resizer : null}
</div>
);
});

function getAriaSort(canSort: boolean, sortDir: string | undefined): "ascending" | "descending" | "none" | undefined {
if (!canSort) {
return undefined;
}

switch (sortDir) {
case "asc":
return "ascending";
case "desc":
return "descending";
default:
return "none";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import classNames from "classnames";
import { HTMLAttributes, KeyboardEvent, ReactElement, ReactNode } from "react";
import { FaArrowsAltV } from "./icons/FaArrowsAltV";
import { FaLongArrowAltDown } from "./icons/FaLongArrowAltDown";
import { FaLongArrowAltUp } from "./icons/FaLongArrowAltUp";
import { useColumn, useHeaderDndVM } from "../model/hooks/injection-hooks";
import { observer } from "mobx-react-lite";
import { SortDirection } from "../typings/sorting";

interface SortIconProps {
direction: SortDirection | undefined;
}

export const ColumnHeader = observer(function ColumnHeader(): ReactElement {
const column = useColumn();
const { header, canSort, alignment } = column;
const caption = header.trim();
const sortProps = canSort ? getSortProps(() => column.toggleSort()) : null;
const vm = useHeaderDndVM();

return (
<div
className={classNames("column-header", { clickable: canSort }, `align-column-${alignment}`)}
style={{ pointerEvents: vm.isDragging ? "none" : undefined }}
{...sortProps}
aria-label={canSort ? "sort " + caption : caption}
>
<span className="column-caption">{caption.length > 0 ? caption : "\u00a0"}</span>
{canSort ? <SortIcon direction={column.sortDir} /> : null}
</div>
);
});

function SortIcon({ direction }: SortIconProps): ReactNode {
switch (direction) {
case "asc":
return <FaLongArrowAltUp />;
case "desc":
return <FaLongArrowAltDown />;
default:
return <FaArrowsAltV />;
}
}

function getSortProps(toggleSort: () => void): HTMLAttributes<HTMLDivElement> {
return {
onClick: () => {
toggleSort();
},
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
toggleSort();
}
},
role: "button",
tabIndex: 0
};
}
Loading
Loading