diff --git a/src/lib/api/adapters/search.adapter.ts b/src/lib/api/adapters/search.adapter.ts index 0ad04ea9..226bc570 100644 --- a/src/lib/api/adapters/search.adapter.ts +++ b/src/lib/api/adapters/search.adapter.ts @@ -28,6 +28,10 @@ export interface SearchParams { per?: number /** Search filters */ filters?: SearchFilters + /** Sort by column name */ + sortBy?: string + /** Sort order */ + sortOrder?: 'asc' | 'desc' } /** @@ -161,6 +165,14 @@ export class SearchAdapter extends BaseAdapter { body.exclude = params.exclude } + // Include sort parameters if provided + if (params.sortBy) { + body.sort = params.sortBy + } + if (params.sortOrder) { + body.order = params.sortOrder + } + // Build filters based on what's allowed for this search type if (params.filters) { const filters: any = {} diff --git a/src/lib/providers/DatabaseProvider.ts b/src/lib/providers/DatabaseProvider.ts index 4b406c4f..07bec809 100644 --- a/src/lib/providers/DatabaseProvider.ts +++ b/src/lib/providers/DatabaseProvider.ts @@ -1,6 +1,7 @@ import { RestDataProvider } from 'wx-grid-data-provider' import { searchAdapter } from '$lib/api/adapters/search.adapter' import type { SearchParams } from '$lib/api/adapters/search.adapter' +import type { SearchFilters } from '$lib/api/adapters/types' interface DatabaseProviderOptions { resource: 'weapons' | 'characters' | 'summons' @@ -24,6 +25,9 @@ export class DatabaseProvider extends RestDataProvider { private totalCount: number = 0 private totalPages: number = 1 private searchQuery: string = '' + private sortColumn: string | null = null + private sortOrder: 'asc' | 'desc' = 'asc' + private filters: SearchFilters = {} constructor(options: DatabaseProviderOptions) { // Pass a dummy URL to parent since we'll override getData @@ -50,7 +54,10 @@ export class DatabaseProvider extends RestDataProvider { const searchParams: SearchParams = { page: page, per: perPage, - ...(this.searchQuery && this.searchQuery.length >= 2 && { query: this.searchQuery }) + ...(this.searchQuery && this.searchQuery.length >= 2 && { query: this.searchQuery }), + ...(this.sortColumn && { sortBy: this.sortColumn }), + ...(this.sortColumn && { sortOrder: this.sortOrder }), + ...(Object.keys(this.filters).length > 0 && { filters: this.filters }) } // Use the appropriate search method based on resource type @@ -120,4 +127,23 @@ export class DatabaseProvider extends RestDataProvider { this.searchQuery = '' this.currentPage = 1 } + + // Set sort column and order + setSort(column: string | null, order: 'asc' | 'desc') { + this.sortColumn = column + this.sortOrder = order + } + + // Set filters + setFilters(filters: SearchFilters) { + this.filters = filters + // Reset to first page when filters change + this.currentPage = 1 + } + + // Clear filters + clearFilters() { + this.filters = {} + this.currentPage = 1 + } } \ No newline at end of file diff --git a/src/lib/types/declarations.d.ts b/src/lib/types/declarations.d.ts index 09a1d978..6e0ef4b4 100644 --- a/src/lib/types/declarations.d.ts +++ b/src/lib/types/declarations.d.ts @@ -50,9 +50,25 @@ declare module 'wx-svelte-grid' { export class Grid extends SvelteComponent<{ data?: IRow[] columns?: IColumn[] + sortMarks?: Record [key: string]: any }> {} + export class Willow extends SvelteComponent<{ + fonts?: boolean + children?: any + }> {} + + export class WillowDark extends SvelteComponent<{ + fonts?: boolean + children?: any + }> {} + + export class Material extends SvelteComponent<{ + fonts?: boolean + children?: any + }> {} + export class RestDataProvider { constructor(url: string, options?: any) getData(): Promise