Article Overview
- Background
- How do you reorder, save, and reset the widgets' position?
- Prerequisites
- Complete example
- View - Dashboard.cshtml
- Controller - HomeController.cs
- MS SQL - Table, User-Defined Table Types, and Stored Procedures
- Example in detail
- View - Dashboard.cshtml
- Model
- Include - links and styles
- Save button for the save operation
- Sortable widgets - with ul element
- Load widgets according to display order
- Save button for the save operation
- Controller - HomeController.cs
- Get the dashboard at load time
- Save action on the save button click
- Get widget method
- Save widget method
- Model UserWidget
- MS SQL
- Table
- User-Defined Table Type
- Stored Procedures for Get and Save
- Output
- View - Dashboard.cshtml
- Summary
- Reference
Background
Let us assume that there is a dashboard with different widgets such as “Top Products by Sales”, “Top Products by Volume”, and “Earning Reports” now, how to add a feature where user can re-arrange the order of widgets according to their own need and save that so that the next time it can be loaded in the order in which it was saved.
Sortable is used to reorder the elements in a list or grid using the mouse.
This is described in this article step by step with a detailed explanation:
- How do you drag and drop widgets using jQuery sortable?
- How to save the latest current positions of the widgets using User-Defined Table Type in MS SQL?
- How to retrieve widget position from the database and display accordingly using custom code?
How to re-order, save, and reset widget positions?
To save the position of draggable widgets, it requires capturing their final position after a drag operation and then persisting that data. The saving method depends on the technology used for the draggable widgets, and the data needs to be stored on the server-side.
The following are the four steps to achieve this.
- Make an element draggable by using the sortable plugin of jQuery.
- Capture the position and send it to the server when the save button is clicked.
- Store data in a database using a stored procedure with a User-Defined Table type in MS SQL.
- Retrieve it on Page Load and re-arrange the widgets with custom logic.
Prerequisites
This example is prepared in .NET MVC using C# and MS SQL stored procedure by User-Defined Table Type and jQuery sortable. Hence, it will be good to have knowledge of these.
Complete Example
The uploaded complete example has mainly three parts.
- View: Dashboard.cshtml
- Controller: HomeController.cs
- MS SQL: Table, User-Defined Table Types, and Stored Procedures
View - Dashboard.cshtml
Client-side user interaction for changing widget positions and sending them for saving.
Controller - HomeController.cs
Server-side logic to save and retrieve data of widgets.
MS SQL - Table, User-Defined Table Types, and Stored Procedures
Tables and stored procedures to perform database operations such as saving and retrieving.
Example in detail
Let's understand the complete code step by step in four groups.
- View: Dashboard.cshtml
- Controller: HomeController.cs
- MS SQL: Table, User-Defined Table Types, and Stored Procedures
- Output: Load time, move widgets, after save
1. View - Dashboard.cshtml
Client-side user interaction for changing widget positions and sending for saving.
- Model
- Include - links and styles
- Save button for the save operation
- Sortable widgets - with UL element
- Load widgets according to display order
- Save button for the save operation
1.1. Model
@model IEnumerable<WebApplication4.Controllers.UserWidget>
1.2. Include - links and styles.
<link rel="stylesheet" href="https://code.jquery.com/ui/1.14.1/themes/base/jquery-ui.css">
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-LN+7fdVzj6u52u30Kp6M/trliBMCMKTyK833zpbD+pXdCLuTusPj697FH4R/5mcr"
crossorigin="anonymous">
<style>
ul {
list-style-type: none;
padding: 5px;
}
</style>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://code.jquery.com/ui/1.14.1/jquery-ui.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q"
crossorigin="anonymous">
</script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
1.3. Save button for save operation.
<button
class="btn"
type="button"
id="btnSave"
title="Save"
onclick="save()"
>
<i class="fas fa-save"></i>
</button>
1.4. Sortable widgets - with UL element.
<ul class="row" id="sortable">
<li class="col-xl-4 col-md-6 li-sortable" id="TopProductsBySales">
<div class="card">
<div class="bg-transparent card-header">
<div class="d-flex flex-wrap align-items-center justify-content-between">
<h5 class="card-title mb-0">Top Products by Sales</h5>
</div>
</div>
<div class="card-body pb-0">
<img src="~/Images/Top Products by Sales.png" width="80%" />
</div>
</div>
</li>
<li class="col-xl-4 col-md-6 li-sortable" id="TopProductsByVolume">
<div class="card">
<div class="bg-transparent card-header">
<div class="d-flex flex-wrap align-items-center justify-content-between">
<h5 class="card-title mb-0">Top Products by Volume</h5>
</div>
</div>
<div class="card-body pb-0">
<img src="~/Images/Top Products by Volume.png" width="80%" />
</div>
</div>
</li>
<li class="col-xl-4 col-md-6 li-sortable" id="EarningReports">
<div class="card">
<div class="bg-transparent card-header">
<div class="d-flex flex-wrap align-items-center justify-content-between">
<h5 class="card-title mb-0">Earning Reports</h5>
</div>
</div>
<div class="card-body pb-0">
<img src="~/Images/Earning Reports.png" width="80%" />
</div>
</div>
</li>
</ul>
1.5. Load widgets according to display order.




Bhavik ChovatiyaPosted Nov 15, 2025, 6:32 AM
Excellent article! The step-by-step approach to creating a static HTML web app using Azure Cloud Shell is very clear and beginner-friendly. I appreciate how you explained setting up the storage account, enabling static website hosting, and uploading files directly from Cloud Shell without requiring local tools. This guide is a great resource for developers looking for a quick and efficient way to host static sites on Azure. Well done!