-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧refactor: add pagination and search component js
- Loading branch information
1 parent
29bb2a0
commit 2ce0c05
Showing
8 changed files
with
137 additions
and
189 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
$(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) { | ||
var start = (page - 1) * rowsPerPage; | ||
var end = start + rowsPerPage; | ||
rows.hide(); | ||
filteredRows.slice(start, end).show(); | ||
} | ||
|
||
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'); | ||
}); | ||
} | ||
displayPage(1); | ||
} | ||
|
||
$("#myInput").on("keyup", function() { | ||
var value = $(this).val().toLowerCase(); | ||
filteredRows = rows.filter(function() { | ||
return $(this).text().toLowerCase().indexOf(value) > -1; | ||
}); | ||
currentPage = 1; // Reset to first page | ||
setupPagination(); | ||
}); | ||
|
||
// Handle row per page selection | ||
$(".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(); | ||
|
||
// Previous and Next button logic | ||
$("#previous-page").on('click', function(e) { | ||
e.preventDefault(); | ||
if (currentPage > 1) { | ||
currentPage--; | ||
displayPage(currentPage); | ||
} | ||
}); | ||
|
||
$("#next-page").on('click', function(e) { | ||
e.preventDefault(); | ||
if (currentPage < pagesCount) { | ||
currentPage++; | ||
displayPage(currentPage); | ||
} | ||
}); | ||
}); |
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
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
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.