svelte-datatables-net
Advanced tools
Comparing version
@@ -30,5 +30,3 @@ import { functionCheckPageNumber } from './functionCheckPageNumber.js'; | ||
const numericRowsPerPage = rowsPerPage === 'all' ? sorted.length : parseInt(rowsPerPage); | ||
const lastPage = numericRowsPerPage === 0 || sorted.length === 0 | ||
? 1 | ||
: Math.ceil(sorted.length / numericRowsPerPage); | ||
const lastPage = Math.ceil(Math.max(1, sorted.length) / Math.max(1, numericRowsPerPage)); | ||
const objeto = { | ||
@@ -38,3 +36,3 @@ original: data, | ||
searched, | ||
paginated: searched.slice(0, numericRowsPerPage), | ||
paginated: sorted.slice(0, numericRowsPerPage), | ||
rowsPerPageString: rowsPerPage, | ||
@@ -44,9 +42,9 @@ rowsPerPage: numericRowsPerPage, | ||
activePage: functionCheckPageNumber(activePage, lastPage) ? activePage : 1, | ||
firstRow: (activePage - 1) * numericRowsPerPage + 1, | ||
lastRow: Math.min(searched.length, activePage * numericRowsPerPage), | ||
firstRow: numericRowsPerPage === 0 ? 0 : (activePage - 1) * numericRowsPerPage + 1, | ||
lastRow: Math.min(sorted.length, activePage * numericRowsPerPage), | ||
searchString, | ||
searchableKeys, | ||
sortFunction: sortFunction, | ||
sortBy: sortBy, | ||
sortOrder: sortOrder, | ||
sortFunction, | ||
sortBy, | ||
sortOrder, | ||
}; | ||
@@ -65,11 +63,13 @@ const estado = $state(objeto); | ||
$effect(() => { | ||
estado.firstRow = (estado.activePage - 1) * estado.rowsPerPage + 1; | ||
estado.rowsPerPage = | ||
estado.rowsPerPageString === 'all' | ||
? estado.sorted.length | ||
: parseInt(estado.rowsPerPageString); | ||
estado.firstRow = | ||
estado.rowsPerPage === 0 ? 0 : (estado.activePage - 1) * estado.rowsPerPage + 1; | ||
estado.lastRow = Math.min(estado.sorted.length, estado.activePage * estado.rowsPerPage); | ||
estado.paginated = estado.sorted.slice(estado.firstRow - 1, estado.lastRow); | ||
estado.lastPage = | ||
estado.rowsPerPage === 0 || estado.sorted.length === 0 | ||
? 1 | ||
: Math.ceil(estado.sorted.length / estado.rowsPerPage); | ||
estado.lastPage = Math.ceil(Math.max(1, estado.sorted.length) / Math.max(1, estado.rowsPerPage)); | ||
}); | ||
return estado; | ||
}; |
{ | ||
"name": "svelte-datatables-net", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "svelte-datatables-net is a svelte/sveltekit component that turns data into an interactive HTML table. Inspired by datatables.net.", | ||
@@ -5,0 +5,0 @@ "repository": { |
31927
0.26%