Add pagination and fix UI total row count

This commit is contained in:
Cristian Ditaputratama 2024-05-04 00:41:28 +07:00
parent 1d65a4fb3e
commit dbc07e66a8
Signed by: ditatompel
GPG key ID: 31D3D06D77950979
2 changed files with 10 additions and 2 deletions

View file

@ -3,7 +3,13 @@
import { format, formatDistance } from 'date-fns'; import { format, formatDistance } from 'date-fns';
import { loadData } from './api-handler'; import { loadData } from './api-handler';
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { DtSrThSort, DtSrThFilter, DtSrRowCount } from '$lib/components/datatables/server'; import {
DtSrRowsPerPage,
DtSrThSort,
DtSrThFilter,
DtSrRowCount,
DtSrPagination
} from '$lib/components/datatables/server';
const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 }); const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 });
let rows = handler.getRows(); let rows = handler.getRows();
@ -64,6 +70,7 @@
<div class="dashboard-card"> <div class="dashboard-card">
<div class="flex justify-between"> <div class="flex justify-between">
<DtSrRowsPerPage {handler} />
<div class="invisible flex place-items-center md:visible"> <div class="invisible flex place-items-center md:visible">
<label for="autoRefreshInterval">Auto Refresh:</label> <label for="autoRefreshInterval">Auto Refresh:</label>
<select <select
@ -116,5 +123,6 @@
<div class="flex justify-between mb-2"> <div class="flex justify-between mb-2">
<DtSrRowCount {handler} /> <DtSrRowCount {handler} />
<DtSrPagination {handler} />
</div> </div>
</div> </div>

View file

@ -4,7 +4,7 @@ import { apiUri } from '$lib/utils/common';
export const loadData = async (state) => { export const loadData = async (state) => {
const response = await fetch(apiUri(`/api/v1/prober?${getParams(state)}`)); const response = await fetch(apiUri(`/api/v1/prober?${getParams(state)}`));
const json = await response.json(); const json = await response.json();
state.setTotalRows(json.data.length ?? 0); state.setTotalRows(json.data.total_rows ?? 0);
return json.data.items ?? []; return json.data.items ?? [];
}; };