Filter using picker
This commit is contained in:
parent
85854aa8be
commit
1272414a57
|
@ -15,6 +15,7 @@
|
||||||
export let sort = false
|
export let sort = false
|
||||||
export let autoWidth = false
|
export let autoWidth = false
|
||||||
export let fetchTerm = null
|
export let fetchTerm = null
|
||||||
|
export let searchTerm = null
|
||||||
export let useFetch = false
|
export let useFetch = false
|
||||||
export let customPopoverHeight
|
export let customPopoverHeight
|
||||||
export let customPopoverOffsetBelow
|
export let customPopoverOffsetBelow
|
||||||
|
@ -91,6 +92,7 @@
|
||||||
isPlaceholder={!arrayValue.length}
|
isPlaceholder={!arrayValue.length}
|
||||||
{autocomplete}
|
{autocomplete}
|
||||||
bind:fetchTerm
|
bind:fetchTerm
|
||||||
|
bind:searchTerm
|
||||||
bind:open
|
bind:open
|
||||||
{useFetch}
|
{useFetch}
|
||||||
{isOptionSelected}
|
{isOptionSelected}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
export let autocomplete = false
|
export let autocomplete = false
|
||||||
export let sort = false
|
export let sort = false
|
||||||
export let fetchTerm = null
|
export let fetchTerm = null
|
||||||
|
export let searchTerm = null
|
||||||
export let useFetch = false
|
export let useFetch = false
|
||||||
export let customPopoverHeight
|
export let customPopoverHeight
|
||||||
export let customPopoverOffsetBelow
|
export let customPopoverOffsetBelow
|
||||||
|
@ -45,7 +46,6 @@
|
||||||
export let customAnchor = null
|
export let customAnchor = null
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
let searchTerm = null
|
|
||||||
let button
|
let button
|
||||||
let popover
|
let popover
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
export let tag = null
|
export let tag = null
|
||||||
export let customPopoverOffsetBelow
|
export let customPopoverOffsetBelow
|
||||||
export let customPopoverMaxHeight
|
export let customPopoverMaxHeight
|
||||||
|
export let fetchTerm = null
|
||||||
|
export let searchTerm = null
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -65,6 +67,8 @@
|
||||||
<Picker
|
<Picker
|
||||||
on:click
|
on:click
|
||||||
bind:open
|
bind:open
|
||||||
|
bind:fetchTerm
|
||||||
|
bind:searchTerm
|
||||||
{quiet}
|
{quiet}
|
||||||
{id}
|
{id}
|
||||||
{error}
|
{error}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
let fieldApi
|
let fieldApi
|
||||||
let fieldSchema
|
let fieldSchema
|
||||||
let tableDefinition
|
let tableDefinition
|
||||||
let fetchTerm
|
let searchTerm
|
||||||
|
|
||||||
$: multiselect = fieldSchema?.relationshipType !== "one-to-many"
|
$: multiselect = fieldSchema?.relationshipType !== "one-to-many"
|
||||||
$: linkedTableId = fieldSchema?.tableId
|
$: linkedTableId = fieldSchema?.tableId
|
||||||
|
@ -61,25 +61,20 @@
|
||||||
}, {}),
|
}, {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
$: options = fetchTerm
|
$: options = Object.values(allOptions)
|
||||||
? Object.values(allOptions).filter(row =>
|
|
||||||
row[primaryDisplay].includes(fetchTerm)
|
|
||||||
)
|
|
||||||
: Object.values(allOptions)
|
|
||||||
|
|
||||||
let lastFetchedTerm
|
$: fetchRows(searchTerm, primaryDisplay)
|
||||||
$: fetchRows(fetchTerm)
|
|
||||||
|
|
||||||
const fetchRows = fetchTerm => {
|
const fetchRows = (searchTerm, primaryDisplay) => {
|
||||||
const termChangedSinceFetch = (lastFetchedTerm || "") !== (fetchTerm || "")
|
const allRowsFetched =
|
||||||
|
$fetch.loaded &&
|
||||||
const allRowsFetched = !lastFetchedTerm && !$fetch.hasNextPage
|
!Object.keys($fetch.query.string).length &&
|
||||||
if (!allRowsFetched && termChangedSinceFetch) {
|
!$fetch.hasNextPage
|
||||||
|
if (!allRowsFetched) {
|
||||||
// Don't request until we have the primary display
|
// Don't request until we have the primary display
|
||||||
if (primaryDisplay) {
|
if (primaryDisplay) {
|
||||||
lastFetchedTerm = fetchTerm
|
|
||||||
fetch.update({
|
fetch.update({
|
||||||
query: { string: { [primaryDisplay]: fetchTerm } },
|
query: { string: { [primaryDisplay]: searchTerm } },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,8 +145,8 @@
|
||||||
getOptionValue={option => option._id}
|
getOptionValue={option => option._id}
|
||||||
{placeholder}
|
{placeholder}
|
||||||
sort
|
sort
|
||||||
useFetch
|
useFetch={false}
|
||||||
bind:fetchTerm
|
bind:searchTerm
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</Field>
|
</Field>
|
||||||
|
|
Loading…
Reference in New Issue