Skip to content

Commit

Permalink
sort instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkier committed Dec 14, 2023
1 parent 9d70937 commit 7ffd87f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
15 changes: 11 additions & 4 deletions backend/zeno_backend/database/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,10 +1920,17 @@ async def table_data_paginated(
if sort == "":
sort = "diff"

order_sql = sql.SQL("ORDER BY {} {}").format(
sql.Identifier(sort),
sql.SQL("DESC" if req.sort[1] else "ASC"),
)
if req.sort[0].data_type == MetadataType.NOMINAL:
order_sql = sql.SQL("ORDER BY {} COLLATE numeric {}").format(
sql.Identifier(sort),
sql.SQL("ASC" if req.sort[1] else "DESC"),
)
else:
order_sql = sql.SQL("ORDER BY {} {}").format(
sql.Identifier(sort),
sql.SQL("ASC" if req.sort[1] else "DESC"),
)

else:
await cur.execute(
sql.SQL("SELECT column_id FROM {} WHERE type = 'ID';").format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import { goto } from '$app/navigation';
import ListView from '$lib/components/instances/ListView.svelte';
import Select from '$lib/components/ui/Select.svelte';
import { model, models, project } from '$lib/stores';
import { columns, model, models, project, sort } from '$lib/stores';
import Button from '@smui/button/src/Button.svelte';
$: sortedModels = $models.sort((a, b) => a.localeCompare(b));
$: console.log($sort);
</script>

<div class="flex min-h-0 w-full min-w-0 items-center pb-2">
Expand All @@ -18,6 +19,24 @@
})
]}
/>
<p class="ml-2 mr-2 font-semibold text-grey-dark">sort by:</p>
<Select
bind:value={$sort[0]}
options={[
...$columns.map((column) => {
return { value: column, label: column.name };
})
]}
/>
<div class="ml-2">
<Select
bind:value={$sort[1]}
options={[
{ value: true, label: 'ascending' },
{ value: false, label: 'descending' }
]}
/>
</div>
<Button
on:click={() => goto(`/project/${$project.uuid}/${encodeURIComponent($project.name)}/explore`)}
class="ml-auto">Explore</Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
selectionIds,
selections,
slices,
sort,
tagIds,
tags
} from '$lib/stores.js';
import { setURLParameters } from '$lib/util/util.js';
import { ZenoColumnType } from '$lib/zenoapi/index.js';
export let data;
Expand Down Expand Up @@ -55,6 +57,7 @@
return tag.dataIds;
})
);
sort.set([data.columns.find((col) => col.columnType === ZenoColumnType.ID), true]);
model.subscribe((mod) => {
if ($comparisonModel && $comparisonModel === mod) {
Expand Down

0 comments on commit 7ffd87f

Please sign in to comment.