
All Snippets
Snippet features
Search dataset using text input
Clear the search using a button
Show results count using a text element
New to our site? Please see our quick tutorial on how to work with our snippets
Setting | Description |
|---|---|
$w.onReady(() => {
DatasetSearch({
inputId: '#input1',
fieldIds: ['title', 'more', 'fieldIds'],
datasetId: '#dynamicDataset',
buttonClearSearchId: '#addButtonIdOrIgnoreThisSetting',
textCounterId: '#addTextIdOrIgnoreThisSetting',
minChars: 3
})
})
async function DatasetSearch({datasetId:t,inputId:e,fieldIds:n,buttonClearSearchId:i,textCounterId:o,minChars:a,onChange:r=null,debounceDelay:c=300}){
if(!e||!t||!n)return;const u=$w(e);if(!u?.id)return;const s=$w(t)
;if(!s?.id)return;await s.onReadyAsync();const d=o?$w(o):{};w()
;const l=require("wix-data"),f=debounce((async()=>{const t=u.value
;if(t.length>=a){
const e=n.reduce(((e,n)=>e.or(l.filter().contains(n,t))),l.filter())
;await s.setFilter(e)}else await s.setFilter(l.filter())
;w(),"function"==typeof r&&r()}),c);if(i){const t=$w(i);t?.id&&t.onClick((()=>{
u.value="",f()}))}function w(){d?.id&&(d.text=s.getTotalCount()+"")}
s.onCurrentIndexChanged(w),u.onKeyPress(f)}function debounce(t,e){let n
;return function(...i){const o=this;n&&clearTimeout(n),n=setTimeout((()=>{
t.apply(o,i)}),e)}}

Title

Title
.png)