Skip to content

Commit

Permalink
Only paginate datatable if per_page is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodwyer committed Sep 12, 2024
1 parent 217f72f commit 8ac805a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions airlock/templates/_components/datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<table
class="{{ class }} hidden"
data-datatable
{% if paging and per_page %}
{% if per_page %}
data-per-page="{{ per_page }}"
{% endif %}
{% attrs id data-column-filter=column_filter data-paging=paging data-sortable=sortable data-searchable=searchable %}
{% attrs id data-column-filter=column_filter data-sortable=sortable data-searchable=searchable %}
>
{{ children }}
</table>
Expand Down
2 changes: 1 addition & 1 deletion airlock/templates/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% #card title="Recent activity" class="mt-5" %}
{% if activity %}
{% #datatable paging per_page="10" column_filter searchable sortable %}
{% #datatable per_page="10" column_filter searchable sortable %}
<thead>
<tr>
<th>
Expand Down
3 changes: 2 additions & 1 deletion assets/src/scripts/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ function buildTables() {

datatableEls?.forEach((table) => {
const columnFilter = table.hasAttribute("data-column-filter");
const paging = table.hasAttribute("data-paging");
const searchable = table.hasAttribute("data-searchable");
const sortable = table.hasAttribute("data-sortable");

let paging = false;
let perPage = undefined;
if (table.hasAttribute("data-per-page")) {
const dataPerPage = table.getAttribute("data-per-page");
if (dataPerPage !== null && hasOnlyDigits(dataPerPage)) {
paging = true;
perPage = parseInt(dataPerPage);
}
}
Expand Down

0 comments on commit 8ac805a

Please sign in to comment.