@page
@model MineMaterialPageModel
@using System.Text.Json
@{
ViewData["Title"] = "Mine Materials";
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"]</title>
<!-- Include DataTables CSS -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">
<!-- Optional: Include Bootstrap CSS for styling -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h2>Mine Materials</h2>
<table id="DT_load" class="display table table-bordered" style="width:100%">
<thead>
<tr>
<th>Mineral Material Name</th>
<th>Limit Grade</th>
<th>Average Grade</th>
<th>Ash Percentage</th>
<th>Special Weight</th>
<th>Definitive Save</th>
<th>Probable Save</th>
<th>Year Extraction Weight</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Data will be populated by DataTables -->
</tbody>
</table>
</div>
<!-- Include jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<!-- Include DataTables JS -->
<script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<!-- Optional: Include Bootstrap JS for styling -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Serialize the C# list to JSON and assign it to a JavaScript variable
var mineMaterialData = @Html.Raw(JsonSerializer.Serialize(Model.MyMineMaterialList));
function loadList() {
var dataTable = $('#DT_load').DataTable({
"data": mineMaterialData,
"columns": [
{ "data": "MineralMaterial.Name", "width": "25%" },
{ "data": "LimitGrade", "width": "10%" },
{ "data": "AverageGrade", "width": "10%" },
{ "data": "AshPercentage", "width": "20%" },
{ "data": "SpecialWeight", "width": "20%" },
{ "data": "DefinitiveSave", "width": "20%" },
{ "data": "ProbableSave", "width": "20%" },
{ "data": "YearExtractionWeight", "width": "20%" },
{
"data": "Id",
"render": function (data, type, row, meta) {
return `
<div class="text-center">
<button class="btn btn-danger text-white" style="cursor:pointer;" type="button" onclick="DeleteRow(${data})">
حذف <i class="glyphicon glyphicon-trash"></i>
</button>
</div>`;
}, "width": "15%"
}
],
bLengthChange: false,
paging: true,
searching: false,
ordering: true,
"language": {
"url": "/js/PersianDataTable.json"
},
"width": "100%"
});
}
// Initialize the DataTable when the document is ready
$(document).ready(function () {
loadList();
});
// Example DeleteRow function
function DeleteRow(id) {
if (confirm("آیا مطمئن هستید که میخواهید این ردیف را حذف کنید؟")) {
// Implement your deletion logic here
// For example, remove the row from the DataTable
var table = $('#DT_load').DataTable();
var row = table.row(function (idx, data, node) {
return data.Id === id;
});
if (row) {
row.remove().draw();
alert("ردیف با موفقیت حذف شد.");
} else {
alert("ردیفی با این شناسه پیدا نشد.");
}
// If you need to also delete from the server, make an AJAX call here
}
}
</script>
</body>
</html>