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

View File

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