-
Notifications
You must be signed in to change notification settings - Fork 0
/
section-9-national-park-js.txt
58 lines (55 loc) · 1.81 KB
/
section-9-national-park-js.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var dataTable;
$(document).ready(function () {
loadDataTable();
});
function loadDataTable() {
dataTable = $('#tblData').DataTable({
"ajax": {
"url": "/nationalParks/GetAllNationalPark",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "name", "width": "50%" },
{ "data": "state", "width": "20%" },
{
"data": "id",
"render": function (data) {
return `<div class="text-center">
<a href="/nationalParks/Upsert/${data}" class='btn btn-success text-white'
style='cursor:pointer;'> <i class='far fa-edit'></i></a>
<a onclick=Delete("/nationalParks/Delete/${data}") class='btn btn-danger text-white'
style='cursor:pointer;'> <i class='far fa-trash-alt'></i></a>
</div>
`;
}, "width": "30%"
}
]
});
}
function Delete(url) {
swal({
title: "Are you sure you want to Delete?",
text: "You will not be able to restore the data!",
icon: "warning",
buttons: true,
dangerMode: true
}).then((willDelete) => {
if (willDelete) {
$.ajax({
type: 'DELETE',
url: url,
success: function (data) {
if (data.success) {
toastr.success(data.message);
dataTable.ajax.reload();
}
else {
toastr.error(data.message);
}
}
});
}
});
}