Skip to content

Commit

Permalink
Implement DataTable for user and world management.
Browse files Browse the repository at this point in the history
  • Loading branch information
BusterNeece committed Jul 23, 2024
1 parent 7b7d5f6 commit 4832493
Show file tree
Hide file tree
Showing 5 changed files with 565 additions and 78 deletions.
39 changes: 4 additions & 35 deletions backend/templates/dashboard/admin/users.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,11 @@
{% block head %}
{{ parent() }}

<script>
function doFilter(filter, selector) {
if (filter === '') {
$(selector).removeClass('d-none');
} else {
$(selector).each(function() {
const searchData = $.map(
$(this).find('.search'),
function(element) {
return $(element).text()
}
).join(' ');
if (!searchData.toUpperCase().includes(filter)) {
$(this).addClass('d-none');
} else {
$(this).removeClass('d-none');
}
});
}
}
function filterTable(event) {
doFilter(
event.target.value.toUpperCase(),
'#data_table tbody tr'
);
}
{{ renderAssets('frontend/dataTable.js') }}

<script>
ready(() => {
document.querySelector('#search_input').addEventListener('load', filterTable, false);
document.querySelector('#search_input').addEventListener('keyup', filterTable, false);
let dataTable = new DataTable('#data_table');
});
</script>
{% endblock %}
Expand All @@ -53,10 +26,6 @@

<div class="card">
<div class="card-body">
<input id="search_input" class="form-control" value="" type="text" Placeholder="Search..." />

<br>

<table class="table table-sm table-striped table-bordered align-middle mb-0" id="data_table">
<thead>
<tr>
Expand All @@ -67,7 +36,7 @@
<th scope="col" style="width:10%">Team?</th>
<th scope="col" style="width:10%">DJ?</th>
<th scope="col" style="width:10%">Banned?</th>
<th scope="col" style="width:15%">Actions</th>
<th data-dt-order="disable" scope="col" style="width:15%">Actions</th>
</tr>
</thead>
<tbody>
Expand Down
55 changes: 12 additions & 43 deletions backend/templates/dashboard/admin/worlds/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,11 @@
{% block head %}
{{ parent() }}

<script>
function doFilter(filter, selector) {
if (filter === '') {
$(selector).removeClass('d-none');
} else {
$(selector).each(function() {
const searchData = $.map(
$(this).find('.search'),
function(element) {
return $(element).text()
}
).join(' ');
if (!searchData.toUpperCase().includes(filter)) {
$(this).addClass('d-none');
} else {
$(this).removeClass('d-none');
}
});
}
}
function filterTable(event) {
doFilter(
event.target.value.toUpperCase(),
'#data_table tbody tr'
);
}
{{ renderAssets('frontend/dataTable.js') }}

<script>
ready(() => {
document.querySelector('#search_input').addEventListener('load', filterTable, false);
document.querySelector('#search_input').addEventListener('keyup', filterTable, false);
let dataTable = new DataTable('#data_table');
});
</script>
{% endblock %}
Expand All @@ -53,30 +26,26 @@

<div class="card">
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<div class="flex-fill">
<input id="search_input" class="form-control" value="" type="text" Placeholder="Search..." />
</div>
<div class="ms-3 flex-shrink-0">
<a href="{{ urlFor('dashboard:admin:worlds:create') }}" class="btn btn btn-success">
Add New Spotlighted World
</a>
</div>
<div class="buttons mb-3">
<a href="{{ urlFor('dashboard:admin:worlds:create') }}" class="btn btn btn-success">
<i class="bi-plus-circle-fill"></i> Add New Spotlighted World
</a>
</div>

<table class="table table-sm table-striped table-bordered align-middle mb-0" id="data_table">
<table class="table table-sm table-striped table-bordered align-middle mb-0" id="data_table"
data-order="[[1, &quot;asc&quot;]]">
<thead>
<tr>
<th scope="col" style="width:15%">Image</th>
<th data-dt-order="disable" scope="col" style="width:15%">Image</th>
<th scope="col" style="width:70%">World Name</th>
<th scope="col" style="width:15%">Actions</th>
<th data-dt-order="disable" scope="col" style="width:15%">Actions</th>
</tr>
</thead>
<tbody>
{% for row in worlds %}
<tr>
<td>
<img src="{{ mediaUrl(row.image) }}" style="max-width: 128px;">
<img src="{{ mediaUrl(row.image) }}" alt="World Image" loading="lazy" style="max-width: 128px;">
</td>
<th class="search" scope="row">{{ row.title }}</th>
<td>
Expand Down
4 changes: 4 additions & 0 deletions frontend/dataTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import DataTable from 'datatables.net-bs5';
import "datatables.net-bs5/css/dataTables.bootstrap5.css";

window.DataTable = DataTable;
Loading

0 comments on commit 4832493

Please sign in to comment.