Skip to content

feat(table):当表格存在固定列时,只允许相同属性列之间相互交换列顺序#8059

Open
Tony-ST0754 wants to merge 2 commits into
mainfrom
feat-table-fixed-drag
Open

feat(table):当表格存在固定列时,只允许相同属性列之间相互交换列顺序#8059
Tony-ST0754 wants to merge 2 commits into
mainfrom
feat-table-fixed-drag

Conversation

@Tony-ST0754
Copy link
Copy Markdown
Collaborator

@Tony-ST0754 Tony-ST0754 commented May 27, 2026

feat(table):当表格存在固定列时,只允许相同属性列之间相互交换列顺序

Link issues

fixes #8058

问题描述 / Problem Description

  • Table组件中AllowDragColumn属性为true时,且组件中存在数据列属性为Fixedtrue时,目前没有控制固定列与非固定列之间不能交换顺序,这样用户在操作时,如果错误的将固定列拖拽到非固定列后面或者将非固定列拖拽到固定列前面时,整个表格组件显示会出现错位

解决方案 / Solution

  • 因此,为避免用户错误操作,将组件调整为:只允许固定列与固定列之间相互交换列顺序,非固定列与非固定列之间相互交换列顺序
  • 同时,为避免表格中固定列(存在多个固定列),未设置列宽时,即未设置Width值时,导致,计算问题出现错位,因此,在组件中列Fixed属性为true时,但未设置Width值时,组件内部会给Width默认值,且默认值为100

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch
  • - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ] - [ ]

Summary by Sourcery

Restrict table column drag-and-drop reordering when fixed columns are present and assign a default width to fixed columns without an explicit width.

New Features:

  • Limit column drag-and-drop so only columns with the same fixed state (fixed-to-fixed or non-fixed-to-non-fixed) can swap positions.

Bug Fixes:

  • Prevent layout misalignment caused by dragging fixed columns across non-fixed columns and by fixed columns without explicit widths.

Enhancements:

  • Automatically apply a default width of 100px to fixed columns when no width is specified to keep fixed-column positioning consistent.

feat(table):当表格存在固定列时,只允许相同属性列之间相互交换列顺序
@bb-auto
Copy link
Copy Markdown

bb-auto Bot commented May 27, 2026

Thanks for your PR, @Tony-ST0754. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@bb-auto bb-auto Bot added the enhancement New feature or request label May 27, 2026
@bb-auto bb-auto Bot requested a review from ArgoZhang May 27, 2026 02:18
@bb-auto bb-auto Bot added this to the v10.6.0 milestone May 27, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 27, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Restricts table column drag-and-drop so that fixed and non-fixed columns can only swap order within their own group, and assigns a default width to fixed columns without an explicit Width to avoid misalignment when reordering.

Sequence diagram for restricted table column drag-and-drop

sequenceDiagram
    actor User
    participant Table as Table
    participant Th as TableHeaderTh

    User->>Th: dragstart
    Th->>Table: setDraggable_dragstart_handler
    Table->>Table: dragItem = col
    Table->>Table: dragItemIsFixed = col.classList.contains('fixed')

    User->>Th: dragover
    Th->>Table: setDraggable_dragover_handler
    Table->>Table: isOverFixed = col.classList.contains('fixed')
    alt [dragItemIsFixed != isOverFixed]
        Table->>Th: e.dataTransfer.dropEffect = none
        Table-->>User: disallow_drop
    else [dragItemIsFixed == isOverFixed]
        Table->>Th: e.dataTransfer.dropEffect = move
        Table-->>User: allow_drop
    end
Loading

File-Level Changes

Change Details Files
Constrain drag-and-drop column reordering to only allow swaps between columns with the same fixed/non-fixed status.
  • Track whether the currently dragged header cell is a fixed column when drag starts.
  • On dragover, determine whether the target column is fixed and block the drop (set dropEffect to none and exit) if the fixed status differs from the dragged column.
  • Keep existing drag-and-drop behavior unchanged when source and target columns share the same fixed status.
src/BootstrapBlazor/Components/Table/Table.razor.js
Ensure fixed table columns without an explicit width receive a default width to prevent misalignment after reordering.
  • In the TableColumn OnInitialized lifecycle method, assign Width = 100 when the column is fixed and no Width is provided, leaving non-fixed column widths unchanged.
  • Document via comments that defaulting width for fixed columns avoids incorrect left-position calculations when reordering.
src/BootstrapBlazor/Components/Table/TableColumn.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#8058 When the Table component has fixed columns and column dragging is enabled, restrict column drag so that only fixed columns can swap order with fixed columns, and non-fixed columns can swap order only with non-fixed columns (no swapping between fixed and non-fixed columns).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In Table.razor.js, consider resetting dragItemIsFixed in the dragend handler (similar to dragItem = null) to avoid stale state if a drag is canceled or future logic depends on this flag being accurate outside an active drag.
  • The condition dragItemIsFixed != isOverFixed in the dragover handler could be made more explicit (e.g., by early-returning when dragItem is null and using strict equality !==) to avoid unexpected behavior if the drag state or CSS classes change.
  • The default-width assignment Width = Fixed ? Width ?? 100 : Width; in OnInitialized only runs once; if Fixed or Width are updated dynamically after initialization, the defaulting logic will not reapply—consider moving this to a place that runs when parameters change if dynamic column configuration is expected.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Table.razor.js`, consider resetting `dragItemIsFixed` in the `dragend` handler (similar to `dragItem = null`) to avoid stale state if a drag is canceled or future logic depends on this flag being accurate outside an active drag.
- The condition `dragItemIsFixed != isOverFixed` in the `dragover` handler could be made more explicit (e.g., by early-returning when `dragItem` is null and using strict equality `!==`) to avoid unexpected behavior if the drag state or CSS classes change.
- The default-width assignment `Width = Fixed ? Width ?? 100 : Width;` in `OnInitialized` only runs once; if `Fixed` or `Width` are updated dynamically after initialization, the defaulting logic will not reapply—consider moving this to a place that runs when parameters change if dynamic column configuration is expected.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor/Components/Table/Table.razor.js" line_range="853-857" />
<code_context>
         })
         EventHandler.on(col, 'dragover', e => {
             e.preventDefault()
+            const isOverFixed = col.classList.contains('fixed') ? true : false;
+            if (dragItemIsFixed != isOverFixed) {
+                // 表格中只允相同属性列间相互交换顺序,即fixed列之间可以交换顺序,fixed列与非fixed列不允许交换顺序
+                e.dataTransfer.dropEffect = 'none'
+                return false;
+            }
+
</code_context>
<issue_to_address>
**suggestion:** Use strict comparison and reconsider `return false` in the dragover handler.

You can simplify this to use strict comparison and avoid implicit coercion:

```js
const isOverFixed = col.classList.contains('fixed');
if (dragItemIsFixed !== isOverFixed) {
  e.dataTransfer.dropEffect = 'none';
  return; // or just fall through
}
```
Also, `return false` in an `addEventListener` handler has no special behavior (unlike inline HTML handlers), and `e.preventDefault()` already controls the default action, so it’s clearer to drop the boolean return.

Suggested implementation:

```javascript
            dragItem = col
            dragItemIsFixed = col.classList.contains('fixed')
            e.dataTransfer.effectAllowed = 'move'
        })

```

```javascript
        EventHandler.on(col, 'dragover', e => {
            e.preventDefault()
            const isOverFixed = col.classList.contains('fixed')
            if (dragItemIsFixed !== isOverFixed) {
                // 表格中只允相同属性列间相互交换顺序,即fixed列之间可以交换顺序,fixed列与非fixed列不允许交换顺序
                e.dataTransfer.dropEffect = 'none'
                return
            }

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +853 to +857
const isOverFixed = col.classList.contains('fixed') ? true : false;
if (dragItemIsFixed != isOverFixed) {
// 表格中只允相同属性列间相互交换顺序,即fixed列之间可以交换顺序,fixed列与非fixed列不允许交换顺序
e.dataTransfer.dropEffect = 'none'
return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use strict comparison and reconsider return false in the dragover handler.

You can simplify this to use strict comparison and avoid implicit coercion:

const isOverFixed = col.classList.contains('fixed');
if (dragItemIsFixed !== isOverFixed) {
  e.dataTransfer.dropEffect = 'none';
  return; // or just fall through
}

Also, return false in an addEventListener handler has no special behavior (unlike inline HTML handlers), and e.preventDefault() already controls the default action, so it’s clearer to drop the boolean return.

Suggested implementation:

            dragItem = col
            dragItemIsFixed = col.classList.contains('fixed')
            e.dataTransfer.effectAllowed = 'move'
        })
        EventHandler.on(col, 'dragover', e => {
            e.preventDefault()
            const isOverFixed = col.classList.contains('fixed')
            if (dragItemIsFixed !== isOverFixed) {
                // 表格中只允相同属性列间相互交换顺序,即fixed列之间可以交换顺序,fixed列与非fixed列不允许交换顺序
                e.dataTransfer.dropEffect = 'none'
                return
            }

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fe72680) to head (a739ed4).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8059   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34155     34156    +1     
  Branches      4697      4698    +1     
=========================================
+ Hits         34155     34156    +1     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

revert: 将数据列Fixed属性为true时,Column的Width默认宽度设置为200,保持与组件中DefaultFixedColumnWidth属性一致
@Tony-ST0754 Tony-ST0754 force-pushed the feat-table-fixed-drag branch from 44f2dff to a739ed4 Compare May 27, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

2 participants