Fix resetting filters and sorting options when changing tables

This commit is contained in:
Andrew Kingston 2021-09-29 10:17:12 +01:00
parent 5e2ba8c45f
commit 4a827c2aab
2 changed files with 16 additions and 15 deletions

View File

@ -14,25 +14,21 @@
import { fetchTableData } from "helpers/fetchTableData" import { fetchTableData } from "helpers/fetchTableData"
import { Pagination } from "@budibase/bbui" import { Pagination } from "@budibase/bbui"
const search = fetchTableData()
let hideAutocolumns = true let hideAutocolumns = true
let filters
$: isUsersTable = $tables.selected?._id === TableNames.USERS $: isUsersTable = $tables.selected?._id === TableNames.USERS
$: title = $tables.selected?.name
$: schema = $tables.selected?.schema $: schema = $tables.selected?.schema
$: type = $tables.selected?.type $: type = $tables.selected?.type
$: isInternal = type !== "external" $: isInternal = type !== "external"
$: id = $tables.selected?._id $: id = $tables.selected?._id
$: search = searchTable(id)
$: columnOptions = Object.keys($search.schema || {}) $: columnOptions = Object.keys($search.schema || {})
$: fetchTable(id, filters)
// Fetches new data whenever the table changes // Fetches new data whenever the table changes
const fetchTable = (tableId, filters) => { const searchTable = tableId => {
search.update({ return fetchTableData({
tableId, tableId,
schema, schema,
filters,
limit: 10, limit: 10,
paginate: true, paginate: true,
}) })
@ -45,14 +41,21 @@
sortOrder: e.detail.order, sortOrder: e.detail.order,
}) })
} }
// Fetch data whenever filters change
const onFilter = e => {
search.update({
filters: e.detail,
})
}
</script> </script>
<div> <div>
<Table <Table
{title} title={$tables.selected?.name}
{schema} {schema}
{type} {type}
tableId={$tables.selected?._id} tableId={id}
data={$search.rows} data={$search.rows}
bind:hideAutocolumns bind:hideAutocolumns
loading={$search.loading} loading={$search.loading}
@ -80,11 +83,9 @@
<HideAutocolumnButton bind:hideAutocolumns /> <HideAutocolumnButton bind:hideAutocolumns />
<!-- always have the export last --> <!-- always have the export last -->
<ExportButton view={$tables.selected?._id} /> <ExportButton view={$tables.selected?._id} />
<TableFilterButton {#key id}
{schema} <TableFilterButton {schema} on:change={onFilter} />
{filters} {/key}
on:change={e => (filters = e.detail)}
/>
{/if} {/if}
</Table> </Table>
<div class="pagination"> <div class="pagination">

View File

@ -95,7 +95,7 @@
<Layout noPadding> <Layout noPadding>
<Body size="S"> <Body size="S">
{#if !filters?.length} {#if !filters?.length}
Add your first filter column. Add your first filter expression.
{:else} {:else}
Results are filtered to only those which match all of the following Results are filtered to only those which match all of the following
constraints. constraints.