fix/doble-click
This commit is contained in:
@@ -7,11 +7,19 @@
|
||||
columns: ColumnDef<TData, TValue>[];
|
||||
data: TData[];
|
||||
onRowClick?: (row: TData) => void;
|
||||
onRowDoubleClick?: (row: TData) => void;
|
||||
selectedId?: string | number | null;
|
||||
idField?: keyof TData;
|
||||
};
|
||||
|
||||
let { data, columns, onRowClick, selectedId, idField }: DataTableProps<TData, TValue> = $props();
|
||||
let {
|
||||
data,
|
||||
columns,
|
||||
onRowClick,
|
||||
onRowDoubleClick,
|
||||
selectedId,
|
||||
idField
|
||||
}: DataTableProps<TData, TValue> = $props();
|
||||
|
||||
const table = $derived(
|
||||
createSvelteTable({
|
||||
@@ -46,6 +54,7 @@
|
||||
{#each table.getRowModel().rows as row (row.id)}
|
||||
<Table.Row
|
||||
onclick={() => onRowClick?.(row.original)}
|
||||
ondblclick={() => onRowDoubleClick?.(row.original)}
|
||||
class="cursor-pointer transition-colors hover:bg-muted/50 {selectedId &&
|
||||
idField &&
|
||||
row.original[idField] === selectedId
|
||||
|
||||
@@ -115,6 +115,10 @@
|
||||
function selectItem(item: CustomsBroker) {
|
||||
selectedItem = item;
|
||||
}
|
||||
function handleRowDoubleClick(item: CustomsBroker) {
|
||||
selectedItem = item;
|
||||
goto(`/dashboard/customs_brokers/edit/${item.broker_key}`);
|
||||
}
|
||||
function handleEdit() {
|
||||
if (selectedItem) goto(`/dashboard/customs_brokers/edit/${selectedItem.broker_key}`);
|
||||
}
|
||||
@@ -265,6 +269,7 @@
|
||||
data={paginatedItems}
|
||||
columns={brokerColumns}
|
||||
onRowClick={selectItem}
|
||||
onRowDoubleClick={handleRowDoubleClick}
|
||||
selectedId={selectedItem?.broker_key}
|
||||
idField="broker_key"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user