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

fix(Sortable): re-sort by Order through js-interop when items changed #2293

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

capdiem
Copy link
Contributor

@capdiem capdiem commented Dec 23, 2024

When the items change, they should not be rendered in the order of the items. Now, after the items are updated, the UI order should be updated through js-interop based on the Order value during the next rendering.

@capdiem capdiem requested a review from Copilot December 23, 2024 08:22

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/Masa.Blazor/Components/Sortable/MSortableProvider.cs:38

  • Using a constant index '1' in the AddContent method will cause all items to be rendered at the same index. This should be replaced with an incremented variable to ensure each item is rendered at a unique index.
sb.AddContent(1, ItemContent?.Invoke(context));
foreach (var item in Items)
{
Dictionary<string, object?> attrs = new()
{
{ "data-id", ItemKey(item) }
};
var context = new SortableItemContext<TItem>(item, attrs);
sb.AddContent(i++, ItemContent?.Invoke(context));
sb.AddContent(1, ItemContent?.Invoke(context));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that the sequence in the for loop doesn't need to be incremented, as I checked the compiled source code of @foreach in Razor.

@Qinyouzeng Qinyouzeng merged commit bd1d636 into main Dec 23, 2024
1 check passed
@Qinyouzeng Qinyouzeng deleted the bugfix/sortable-items-change branch December 23, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants