update filter functionality
This commit is contained in:
parent
464c62d1e5
commit
9431a0502a
10 changed files with 2362 additions and 220 deletions
|
|
@ -6,7 +6,17 @@
|
|||
Add
|
||||
</button>
|
||||
</div>
|
||||
<DataTable :data="tableData" :columns="columns" :filters="filters" tableName="clients" />
|
||||
<DataTable
|
||||
:data="tableData"
|
||||
:columns="columns"
|
||||
:filters="filters"
|
||||
tableName="clients"
|
||||
:lazy="true"
|
||||
:totalRecords="totalRecords"
|
||||
:loading="isLoading"
|
||||
:onLazyLoad="handleLazyLoad"
|
||||
@lazy-load="handleLazyLoad"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
|
|
@ -15,13 +25,16 @@ import DataTable from "../common/DataTable.vue";
|
|||
import Api from "../../api";
|
||||
import { FilterMatchMode } from "@primevue/core";
|
||||
import { useLoadingStore } from "../../stores/loading";
|
||||
import { usePaginationStore } from "../../stores/pagination";
|
||||
import { useFiltersStore } from "../../stores/filters";
|
||||
|
||||
const loadingStore = useLoadingStore();
|
||||
const paginationStore = usePaginationStore();
|
||||
const filtersStore = useFiltersStore();
|
||||
|
||||
const itemCount = ref(0);
|
||||
const page = ref(0);
|
||||
const pageLength = ref(30);
|
||||
const tableData = ref([]);
|
||||
const totalRecords = ref(0);
|
||||
const isLoading = ref(false);
|
||||
|
||||
const onClick = () => {
|
||||
frappe.new_doc("Customer");
|
||||
|
|
@ -49,23 +62,114 @@ const columns = [
|
|||
{ label: "Payment Received", fieldName: "paymentStatus", type: "status", sortable: true },
|
||||
{ label: "Job Status", fieldName: "jobStatus", type: "status", sortable: true },
|
||||
];
|
||||
onMounted(async () => {
|
||||
if (tableData.value.length > 0) {
|
||||
return;
|
||||
}
|
||||
// Handle lazy loading events from DataTable
|
||||
const handleLazyLoad = async (event) => {
|
||||
console.log("Clients page - handling lazy load:", event);
|
||||
|
||||
try {
|
||||
// Use the loading store to track this API call
|
||||
const data = await loadingStore.withComponentLoading(
|
||||
isLoading.value = true;
|
||||
|
||||
// Get pagination parameters
|
||||
const paginationParams = {
|
||||
page: event.page || 0,
|
||||
pageSize: event.rows || 10,
|
||||
sortField: event.sortField,
|
||||
sortOrder: event.sortOrder,
|
||||
};
|
||||
|
||||
// Get filters (convert PrimeVue format to API format)
|
||||
const filters = {};
|
||||
if (event.filters) {
|
||||
Object.keys(event.filters).forEach((key) => {
|
||||
if (key !== "global" && event.filters[key] && event.filters[key].value) {
|
||||
filters[key] = event.filters[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Check cache first
|
||||
const cachedData = paginationStore.getCachedPage(
|
||||
"clients",
|
||||
() => Api.getClientDetails(),
|
||||
"Loading client data...",
|
||||
paginationParams.page,
|
||||
paginationParams.pageSize,
|
||||
paginationParams.sortField,
|
||||
paginationParams.sortOrder,
|
||||
filters,
|
||||
);
|
||||
tableData.value = data;
|
||||
|
||||
if (cachedData) {
|
||||
// Use cached data
|
||||
tableData.value = cachedData.records;
|
||||
totalRecords.value = cachedData.totalRecords;
|
||||
paginationStore.setTotalRecords("clients", cachedData.totalRecords);
|
||||
|
||||
console.log("Loaded from cache:", {
|
||||
records: cachedData.records.length,
|
||||
total: cachedData.totalRecords,
|
||||
page: paginationParams.page + 1,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Making API call with:", { paginationParams, filters });
|
||||
|
||||
// Call API with pagination and filters
|
||||
const result = await Api.getPaginatedClientDetails(paginationParams, filters);
|
||||
|
||||
// Update local state
|
||||
tableData.value = result.data;
|
||||
totalRecords.value = result.totalRecords;
|
||||
|
||||
// Update pagination store with new total
|
||||
paginationStore.setTotalRecords("clients", result.totalRecords);
|
||||
|
||||
// Cache the result
|
||||
paginationStore.setCachedPage(
|
||||
"clients",
|
||||
paginationParams.page,
|
||||
paginationParams.pageSize,
|
||||
paginationParams.sortField,
|
||||
paginationParams.sortOrder,
|
||||
filters,
|
||||
{
|
||||
records: result.data,
|
||||
totalRecords: result.totalRecords,
|
||||
},
|
||||
);
|
||||
|
||||
console.log("Loaded from API:", {
|
||||
records: result.data.length,
|
||||
total: result.totalRecords,
|
||||
page: paginationParams.page + 1,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error loading client data:", error);
|
||||
// You could also show a toast or other error notification here
|
||||
tableData.value = [];
|
||||
totalRecords.value = 0;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Load initial data
|
||||
onMounted(async () => {
|
||||
// Initialize pagination and filters
|
||||
paginationStore.initializeTablePagination("clients", { rows: 10 });
|
||||
filtersStore.initializeTableFilters("clients", columns);
|
||||
|
||||
// Load first page
|
||||
const initialPagination = paginationStore.getTablePagination("clients");
|
||||
const initialFilters = filtersStore.getTableFilters("clients");
|
||||
|
||||
await handleLazyLoad({
|
||||
page: initialPagination.page,
|
||||
rows: initialPagination.rows,
|
||||
first: initialPagination.first,
|
||||
sortField: initialPagination.sortField,
|
||||
sortOrder: initialPagination.sortOrder,
|
||||
filters: initialFilters,
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<style lang="css"></style>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue