Example of Sorting Cards in ASP.NET MVC Kanban Control
This sample demonstrates the card sorting capabilities of the Kanban component, enabling workflow items to be organized and displayed based on different sorting criteria and orders.
To Do
In Progress
Done
Properties
<template id="kanban-col-todo"><span class="ui-kanban-col-icon ui-kanban-col-todo"></span>To Do</template>
<template id="kanban-col-progress"><span class="ui-kanban-col-icon ui-kanban-col-progress"></span>In Progress</template>
<template id="kanban-col-done"><span class="ui-kanban-col-icon ui-kanban-col-done"></span>Done</template>
@Html.UiKanban(new UiKanbanOptions
{
Id = "sortingBoard",
DataSource = (IEnumerable<object>)ViewData["DataSource"],
Columns = new List<UiKanbanColumn>
{
new UiKanbanColumn { Key = "Open", Text = "To Do", Template = "#kanban-col-todo" },
new UiKanbanColumn { Key = "InProgress", Text = "In Progress", Template = "#kanban-col-progress" },
new UiKanbanColumn { Key = "Done", Text = "Done", Template = "#kanban-col-done" }
},
SortSettings = new UiKanbanSortSettings { SortBy = UiKanbanSortBy.Index, Field = "Order", Direction = UiKanbanSortDirection.Ascending },
Height = "460px",
AriaLabel = "Release workflow board"
})
<div class="demo-property-panel">
<h3>Properties</h3>
<div class="demo-property-row"><label for="sortBy">Sort By</label><select id="sortBy"><option value="DataSourceOrder">DataSourceOrder</option><option value="Index" selected>Index</option><option value="Custom">Custom</option></select></div>
<div class="demo-property-row"><label for="sortField">Field</label><select id="sortField" disabled><option value="Order">Order</option></select></div>
<div class="demo-property-row"><label for="sortDirection">Direction</label><select id="sortDirection"><option>Ascending</option><option>Descending</option></select></div>
<div class="demo-property-row"><button type="button" id="sortCards">Sort</button><button type="button" id="clearSort">Clear</button></div>
</div>
<script>
(function () {
var board = function () { return window.Lumen.get('sortingBoard'); };
var by = document.getElementById('sortBy'), field = document.getElementById('sortField'), direction = document.getElementById('sortDirection');
function fields(list, enabled) {
field.innerHTML = '';
list.forEach(function (name) { var option = document.createElement('option'); option.value = option.textContent = name; field.appendChild(option); });
field.disabled = !enabled;
}
by.addEventListener('change', function () {
if (by.value === 'Custom') { fields(['Header', 'Content', 'Order'], true); }
else { fields([by.value === 'Index' ? 'Order' : 'None'], false); }
});
document.getElementById('sortCards').addEventListener('click', function () {
board().setSortSettings({ sortBy: by.value, field: field.value, direction: direction.value });
});
document.getElementById('clearSort').addEventListener('click', function () {
by.value = 'Index';
direction.value = 'Ascending';
fields(['None'], false);
board().setSortSettings({ sortBy: 'Index', field: 'None', direction: 'Ascending' });
});
}());
</script>
<template id="kanban-col-todo"><span class="ui-kanban-col-icon ui-kanban-col-todo"></span>To Do</template>
<template id="kanban-col-progress"><span class="ui-kanban-col-icon ui-kanban-col-progress"></span>In Progress</template>
<template id="kanban-col-done"><span class="ui-kanban-col-icon ui-kanban-col-done"></span>Done</template>
<style>
.ui-kanban-col-icon { align-items: center; border-radius: 3px; color: #fff; display: inline-flex; font-size: 11px; height: 16px; justify-content: center; margin-right: 8px; width: 16px; }
.ui-kanban-col-todo { background: #2563eb; }
.ui-kanban-col-progress { background: #f59e0b; }
.ui-kanban-col-review { background: #9c27b0; }
.ui-kanban-col-done { background: #43a047; }
.ui-kanban-col-todo::before { content: "\2630"; }
.ui-kanban-col-progress::before { content: "\2731"; }
.ui-kanban-col-review::before { content: "\25C9"; }
.ui-kanban-col-done::before { content: "\2714"; }
</style>
@Html.UiKanban(new UiKanbanOptions
{
Id = "sortingBoard",
DataSource = (IEnumerable<object>)ViewData["DataSource"],
Columns = new List<UiKanbanColumn>
{
new UiKanbanColumn { Key = "Open", Text = "To Do", Template = "#kanban-col-todo" },
new UiKanbanColumn { Key = "InProgress", Text = "In Progress", Template = "#kanban-col-progress" },
new UiKanbanColumn { Key = "Done", Text = "Done", Template = "#kanban-col-done" }
},
SortSettings = new UiKanbanSortSettings { SortBy = UiKanbanSortBy.Index, Field = "Order", Direction = UiKanbanSortDirection.Ascending },
Height = "460px",
AriaLabel = "Release workflow board"
})
<div class="demo-property-panel">
<h3>Properties</h3>
<div class="demo-property-row"><label for="sortBy">Sort By</label><select id="sortBy"><option value="DataSourceOrder">DataSourceOrder</option><option value="Index" selected>Index</option><option value="Custom">Custom</option></select></div>
<div class="demo-property-row"><label for="sortField">Field</label><select id="sortField" disabled><option value="Order">Order</option></select></div>
<div class="demo-property-row"><label for="sortDirection">Direction</label><select id="sortDirection"><option>Ascending</option><option>Descending</option></select></div>
<div class="demo-property-row"><button type="button" id="sortCards">Sort</button><button type="button" id="clearSort">Clear</button></div>
</div>
<script>
(function () {
var board = function () { return window.Lumen.get('sortingBoard'); };
var by = document.getElementById('sortBy'), field = document.getElementById('sortField'), direction = document.getElementById('sortDirection');
function fields(list, enabled) {
field.innerHTML = '';
list.forEach(function (name) { var option = document.createElement('option'); option.value = option.textContent = name; field.appendChild(option); });
field.disabled = !enabled;
}
by.addEventListener('change', function () {
if (by.value === 'Custom') { fields(['Header', 'Content', 'Order'], true); }
else { fields([by.value === 'Index' ? 'Order' : 'None'], false); }
});
document.getElementById('sortCards').addEventListener('click', function () {
board().setSortSettings({ sortBy: by.value, field: field.value, direction: direction.value });
});
document.getElementById('clearSort').addEventListener('click', function () {
by.value = 'Index';
direction.value = 'Ascending';
fields(['None'], false);
board().setSortSettings({ sortBy: 'Index', field: 'None', direction: 'Ascending' });
});
}());
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class KanbanController : Controller
{
// The page is Views/Kanban/SortingCards.cshtml; it draws what ViewData holds.
public ActionResult SortingCards()
{
ViewData["DataSource"] = new List<UiKanbanCard>
{
new UiKanbanCard { Id = "1", Header = "C - Plan", Content = "Third by work order", Status = "Open", Order = 3 },
new UiKanbanCard { Id = "2", Header = "B - Review", Content = "First by work order", Status = "Open", Order = 1 },
new UiKanbanCard { Id = "3", Header = "A - Prepare", Content = "Second by work order", Status = "Open", Order = 2 }
};
return View();
}
private const string Open = "Open";
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
This sample demonstrates the card sorting of the Kanban component using the SortSettings property. The cards of a column are listed by their index (the order of the data), or by a field of their own, in ascending or descending order.
SortBy- Sorts the cards by theirIndex,DataSourceOrderor aCustomfield.Field- The field the cards are sorted by whenSortByisCustom.Direction- Ascending or descending.