Fix resetting filters and sorting options when changing tables
This commit is contained in:
parent
5e2ba8c45f
commit
4a827c2aab
|
@ -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">
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue