diff --git a/BlazorApp/BlazorApp/BlazorApp.csproj b/BlazorApp/BlazorApp/BlazorApp.csproj
index 1bb76d0..0b32f52 100644
--- a/BlazorApp/BlazorApp/BlazorApp.csproj
+++ b/BlazorApp/BlazorApp/BlazorApp.csproj
@@ -7,12 +7,13 @@
-
-
-
+
+
+
+
@@ -25,6 +26,9 @@
+
+
+
diff --git a/BlazorApp/BlazorApp/Components/InventoryComp.razor b/BlazorApp/BlazorApp/Components/InventoryComp.razor
index ab7078a..31d5a00 100644
--- a/BlazorApp/BlazorApp/Components/InventoryComp.razor
+++ b/BlazorApp/BlazorApp/Components/InventoryComp.razor
@@ -50,8 +50,8 @@
TotalItems="@totalItem"
PageSize="10"
ShowPager
-
Sortable="true">
+
diff --git a/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs b/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs
index 6ca14eb..52aa4e4 100644
--- a/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs
+++ b/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs
@@ -26,6 +26,8 @@ namespace BlazorApp.Components
private int totalItem;
+ public bool IsSorted { get; set; }
+
public InventoryComp()
{
this.InventoryItems = new List- { };
@@ -42,16 +44,28 @@ namespace BlazorApp.Components
return;
}
- if (!e.CancellationToken.IsCancellationRequested)
+ if (!e.CancellationToken.IsCancellationRequested && IsSorted ==false)
{
Items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
- }
+ }
+ else
+ {
+ Items = await DataService.SortedList(e.Page, e.PageSize);
+ }
+
}
private async Task SortByName()
{
- Items = await DataService.SortedList();
+ if (IsSorted)
+ {
+ IsSorted = false;
+ }
+ else
+ {
+ IsSorted = true;
+ }
}
void refresh()
diff --git a/BlazorApp/BlazorApp/Services/DataApiService.cs b/BlazorApp/BlazorApp/Services/DataApiService.cs
index 035adb2..407996c 100644
--- a/BlazorApp/BlazorApp/Services/DataApiService.cs
+++ b/BlazorApp/BlazorApp/Services/DataApiService.cs
@@ -57,10 +57,9 @@ namespace BlazorApp.Services
return await _http.GetFromJsonAsync
>("https://localhost:7234/api/Crafting/recipe");
}
- public async Task> SortedList()
+ public async Task> SortedList(int currentPage, int pageSize)
{
- List- it = await _http.GetFromJsonAsync
>($"https://localhost:7234/api/Crafting/all/");
- return it.OrderBy(i => i.DisplayName).ToList();
+ return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
}
diff --git a/BlazorApp/BlazorApp/Services/DataLocalService.cs b/BlazorApp/BlazorApp/Services/DataLocalService.cs
index 3b13a80..d599597 100644
--- a/BlazorApp/BlazorApp/Services/DataLocalService.cs
+++ b/BlazorApp/BlazorApp/Services/DataLocalService.cs
@@ -185,7 +185,7 @@ namespace BlazorApp.Services
return Task.FromResult(items);
}
- public Task> SortedList()
+ public Task> SortedList(int currentPage, int pageSize)
{
throw new NotImplementedException();
}
diff --git a/BlazorApp/BlazorApp/Services/IDataService.cs b/BlazorApp/BlazorApp/Services/IDataService.cs
index a39928c..12d2cdb 100644
--- a/BlazorApp/BlazorApp/Services/IDataService.cs
+++ b/BlazorApp/BlazorApp/Services/IDataService.cs
@@ -14,7 +14,7 @@ namespace BlazorApp.Services
Task Update(int id, ItemModel itemModel);
Task Delete(int id);
Task> GetRecipes();
- Task> SortedList();
+ Task> SortedList(int currentPage, int pageSize);
}
}
diff --git a/BlazorApp/Minecraft.Crafting.Api/Controllers/CraftingController.cs b/BlazorApp/Minecraft.Crafting.Api/Controllers/CraftingController.cs
index 11bb5fa..a916f63 100644
--- a/BlazorApp/Minecraft.Crafting.Api/Controllers/CraftingController.cs
+++ b/BlazorApp/Minecraft.Crafting.Api/Controllers/CraftingController.cs
@@ -214,6 +214,27 @@ namespace Minecraft.Crafting.Api.Controllers
return Task.FromResult(data.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList());
}
+ ///
+ /// Get the sorted items with pagination.
+ ///
+ /// The current page.
+ /// Size of the page.
+ /// The sorted items.
+ [HttpGet]
+ [Route("")]
+ public Task> SortedList(int currentPage, int pageSize)
+ {
+ var data = JsonSerializer.Deserialize>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
+
+ if (data == null)
+ {
+ throw new Exception("Unable to get the items.");
+ }
+
+ var sorted = data.OrderBy(i => i.DisplayName);
+ return Task.FromResult(data.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList());
+ }
+
///
/// Resets the items.
///