Add row click navigation to database grids
This commit is contained in:
parent
6b5f2b4868
commit
45f04c2593
1 changed files with 17 additions and 0 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
import type { IColumn, IRow } from 'wx-svelte-grid'
|
import type { IColumn, IRow } from 'wx-svelte-grid'
|
||||||
import { DatabaseProvider } from '$lib/providers/DatabaseProvider'
|
import { DatabaseProvider } from '$lib/providers/DatabaseProvider'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
resource: 'weapons' | 'characters' | 'summons'
|
resource: 'weapons' | 'characters' | 'summons'
|
||||||
|
|
@ -67,8 +68,23 @@
|
||||||
api = apiRef
|
api = apiRef
|
||||||
// Connect provider to grid
|
// Connect provider to grid
|
||||||
api.setNext(provider)
|
api.setNext(provider)
|
||||||
|
|
||||||
|
// Add row click handler
|
||||||
|
api.on("select-row", (ev: any) => {
|
||||||
|
console.log("Row selected:", ev)
|
||||||
|
const rowId = ev.id
|
||||||
|
if (rowId) {
|
||||||
|
// Find the row data to get the granblue_id
|
||||||
|
const rowData = data.find((item: any) => item.id === rowId)
|
||||||
|
if (rowData && rowData.granblue_id) {
|
||||||
|
console.log(`Navigating to: /database/${resource}/${rowData.granblue_id}`)
|
||||||
|
goto(`/database/${resource}/${rowData.granblue_id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle pagination
|
// Handle pagination
|
||||||
const handlePrevPage = () => {
|
const handlePrevPage = () => {
|
||||||
if (currentPage > 1) {
|
if (currentPage > 1) {
|
||||||
|
|
@ -352,6 +368,7 @@
|
||||||
|
|
||||||
:global(.wx-grid .wx-row:hover) {
|
:global(.wx-grid .wx-row:hover) {
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Element color classes
|
// Element color classes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue