Skip to content

Commit

Permalink
fix: pagination active bug in datatable, close #208
Browse files Browse the repository at this point in the history
  • Loading branch information
zuramai committed Mar 29, 2023
1 parent 50a7ca2 commit 5a91943
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/assets/static/js/pages/datatables.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
let jquery_datatable = $("#table1").DataTable()

const setTableColor = () => {
document.querySelectorAll('.dataTables_paginate .pagination').forEach(dt => {
dt.classList.add('pagination-primary')
})
}
setTableColor()
jquery_datatable.on('draw', setTableColor)
10 changes: 8 additions & 2 deletions src/assets/static/js/pages/simple-datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ function adaptPagination() {
}
}

const refreshPagination = () => {
adaptPagination()
}

// Patch "per page dropdown" and pagination after table rendered
dataTable.on("datatable.init", function () {
dataTable.on("datatable.init", () => {
adaptPageDropdown()
adaptPagination()
refreshPagination()
})
dataTable.on("datatable.update", refreshPagination)
dataTable.on("datatable.sort", refreshPagination)

// Re-patch pagination after the page was changed
dataTable.on("datatable.page", adaptPagination)
2 changes: 1 addition & 1 deletion src/table-datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ <h3>DataTable</h3>
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="assets/extensions/simple-datatables/style.css">
<link rel="stylesheet" href="@/assets/scss/pages/simple-datatables.scss">
<link rel="stylesheet" href="assets/scss/pages/simple-datatables.scss">
{% endblock %}
{% block js %}
<script src="assets/extensions/simple-datatables/umd/simple-datatables.js"></script>
Expand Down

0 comments on commit 5a91943

Please sign in to comment.