-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3245d4c
commit be74f1c
Showing
5 changed files
with
147 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,76 @@ | ||
$(document).ready(function(){ | ||
var rowsPerPage = 10; // Valor inicial | ||
var rows = $('#myTable tr'); | ||
var filteredRows = rows; // Inicialmente, todas las filas son el conjunto filtrado | ||
var pagesCount; | ||
var currentPage = 1; | ||
$(document).ready(function(){ | ||
var rowsPerPage = 10; // Valor inicial | ||
var rows = $('#myTable tr'); | ||
var filteredRows = rows; // Inicialmente, todas las filas son el conjunto filtrado | ||
var pagesCount; | ||
var currentPage = 1; | ||
|
||
function displayPage(page) { | ||
function displayPage(page) { | ||
var start = (page - 1) * rowsPerPage; | ||
var end = start + rowsPerPage; | ||
rows.hide(); | ||
filteredRows.slice(start, end).show(); | ||
} | ||
} | ||
|
||
function setupPagination() { | ||
function setupPagination() { | ||
pagesCount = Math.ceil(filteredRows.length / rowsPerPage); | ||
$('.pagination .number-page').remove(); // Remove old page numbers | ||
for (var i = 1; i <= pagesCount; i++) { | ||
$('<li class="page-item number-page"><a class="page-link" href="#">' + i + '</a></li>') | ||
.insertBefore("#next-page") | ||
.on('click', function(e) { | ||
e.preventDefault(); | ||
currentPage = parseInt($(this).text()); | ||
displayPage(currentPage); | ||
$(".pagination .number-page").removeClass('active'); | ||
$(this).addClass('active'); | ||
}); | ||
$('<li class="page-item number-page"><a class="page-link" href="#">' + i + '</a></li>') | ||
.insertBefore("#next-page") | ||
.on('click', function(e) { | ||
e.preventDefault(); | ||
currentPage = parseInt($(this).text()); | ||
displayPage(currentPage); | ||
$(".pagination .number-page").removeClass('active'); | ||
$(this).addClass('active'); | ||
}); | ||
} | ||
displayPage(1); | ||
} | ||
} | ||
|
||
$("#myInput").on("keyup", function() { | ||
// Event Delegation for edit buttons and other interactive elements | ||
$(document).on('click', '.edit-button', function() { | ||
// Aquí iría el código para manejar la edición | ||
}); | ||
|
||
// Existing search functionality | ||
$("#myInput").on("keyup", function() { | ||
var value = $(this).val().toLowerCase(); | ||
filteredRows = rows.filter(function() { | ||
return $(this).text().toLowerCase().indexOf(value) > -1; | ||
return $(this).text().toLowerCase().indexOf(value) > -1; | ||
}); | ||
currentPage = 1; // Reset to first page | ||
currentPage = 1; | ||
setupPagination(); | ||
}); | ||
}); | ||
|
||
// Handle row per page selection | ||
$(".dropdown-menu a").on("click", function(e) { | ||
// Existing dropdown functionality | ||
$(".dropdown-menu a").on("click", function(e) { | ||
e.preventDefault(); | ||
var selectedValue = $(this).text().trim(); | ||
rowsPerPage = selectedValue.toLowerCase() === 'all' ? rows.length : parseInt(selectedValue); | ||
currentPage = 1; // Reset to first page | ||
setupPagination(); | ||
}); | ||
}); | ||
|
||
// Setup initial pagination | ||
setupPagination(); | ||
// Initial setup | ||
setupPagination(); | ||
|
||
// Previous and Next button logic | ||
$("#previous-page").on('click', function(e) { | ||
// Previous and Next button logic | ||
$("#previous-page").on('click', function(e) { | ||
e.preventDefault(); | ||
if (currentPage > 1) { | ||
currentPage--; | ||
displayPage(currentPage); | ||
currentPage--; | ||
displayPage(currentPage); | ||
} | ||
}); | ||
}); | ||
|
||
$("#next-page").on('click', function(e) { | ||
$("#next-page").on('click', function(e) { | ||
e.preventDefault(); | ||
if (currentPage < pagesCount) { | ||
currentPage++; | ||
displayPage(currentPage); | ||
currentPage++; | ||
displayPage(currentPage); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
d |
85 changes: 85 additions & 0 deletions
85
sld-dashboard/app/base/static/assets/js/pagination_edit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
document.addEventListener("DOMContentLoaded", function() { | ||
var rowsPerPage = 10; | ||
var table = document.getElementById("table"); | ||
var tbody = table.getElementsByTagName("tbody")[0]; | ||
var rows = Array.from(tbody.getElementsByTagName("tr")); | ||
var pagination = document.querySelector(".pagination"); | ||
var currentPage = 1; | ||
|
||
function displayPage(page, rowsToShow) { | ||
var start = (page - 1) * rowsPerPage; | ||
var end = start + rowsPerPage; | ||
rows.forEach(row => row.style.display = "none"); | ||
rowsToShow.slice(start, end).forEach(row => row.style.display = ""); | ||
} | ||
|
||
function setupPagination(rowsToShow) { | ||
pagination.innerHTML = ''; | ||
var pagesCount = Math.ceil(rowsToShow.length / rowsPerPage); | ||
|
||
// Previous page button | ||
var prevPageItem = document.createElement("li"); | ||
prevPageItem.className = "page-item"; | ||
var prevPageLink = document.createElement("a"); | ||
prevPageLink.className = "page-link"; | ||
prevPageLink.href = "#"; | ||
prevPageLink.innerText = "Previous"; | ||
prevPageItem.appendChild(prevPageLink); | ||
pagination.appendChild(prevPageItem); | ||
|
||
// Page number buttons | ||
for (var i = 1; i <= pagesCount; i++) { | ||
var pageItem = document.createElement("li"); | ||
pageItem.className = "page-item"; | ||
var pageLink = document.createElement("a"); | ||
pageLink.className = "page-link"; | ||
pageLink.href = "#"; | ||
pageLink.innerText = i; | ||
pageItem.appendChild(pageLink); | ||
pagination.appendChild(pageItem); | ||
|
||
pageLink.addEventListener("click", function(e) { | ||
e.preventDefault(); | ||
currentPage = parseInt(this.innerText); | ||
displayPage(currentPage, rowsToShow); | ||
}); | ||
} | ||
|
||
// Next page button | ||
var nextPageItem = document.createElement("li"); | ||
nextPageItem.className = "page-item"; | ||
var nextPageLink = document.createElement("a"); | ||
nextPageLink.className = "page-link"; | ||
nextPageLink.href = "#"; | ||
nextPageLink.innerText = "Next"; | ||
nextPageItem.appendChild(nextPageLink); | ||
pagination.appendChild(nextPageItem); | ||
|
||
prevPageLink.addEventListener("click", function(e) { | ||
e.preventDefault(); | ||
if (currentPage > 1) { | ||
displayPage(--currentPage, rowsToShow); | ||
} | ||
}); | ||
|
||
nextPageLink.addEventListener("click", function(e) { | ||
e.preventDefault(); | ||
if (currentPage < pagesCount) { | ||
displayPage(++currentPage, rowsToShow); | ||
} | ||
}); | ||
|
||
displayPage(1, rowsToShow); // Display the first page | ||
} | ||
|
||
function updateSearchAndPagination() { | ||
var filter = document.getElementById("search").value.toUpperCase(); | ||
var filteredRows = rows.filter(row => row.textContent.toUpperCase().indexOf(filter) > -1); | ||
currentPage = 1; | ||
setupPagination(filteredRows); | ||
} | ||
|
||
document.getElementById("search").addEventListener("keyup", updateSearchAndPagination); | ||
|
||
setupPagination(rows); // Initial setup with all rows | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.