The Workforce Scheduling in ASP.NET Core tutorial uses a Queue component which has a similar UI - it’s an ordered list of items which can be moved using drag and drop.
This project uses two fields to handle item order:
When the item (Order
) is moved, the change is recorded in two steps:
-
The Ordinal
value of the moved item is set to the target position
. The OrdinalPriority
is set to the current time.
-
The order is then normalized by calling CompactOrdinals()
method which looks like this:
private async Task CompactOrdinals()
{
List<Order> list = await _context.Orders.Where(e => e.ResourceId == null).OrderBy(e => e.Ordinal)
.ThenByDescending(e => e.OrdinalPriority).ToListAsync();
int i = 0;
foreach (Order order in list)
{
order.Ordinal = i;
i += 1;
}
await _context.SaveChangesAsync();
}
A compacted dataset can be sorted simply using Ordinal
.
This is not the only way to implement it, but you can adapt this aproach for use with Kanban.
Instead of maintaining the order for each cell separately, it is probably easier to have a single global index. In that case, you need to use the new global position of a card instead of the position inside a cell (args.position
).
You can get the new global using cards.list.indexOf(args.card.data)
in onCardMoved
.