Filter with checkboxes

Ok, now i understand you.

I need a code who shows me all results that have " boolean1 " or " boolean2 " checked in the database.
Would a table suffice for this purpose or what do you need the data for?
If YES —> just connect a table to your dataset. It will show the results.
And you even do not need any code for it.

If NOT —> then you can do it like here in this example.

You just have to call “getItems()” again, after you have setted and ran your filter.

Create a button on your page —> “button1” and give it an “onClick-EventHandler”

export function button1_click(event) {show_results()}

And add this code here to your page…

function show_results (parameter) {
    $w("#dataset1").onReady( () => {       
        $w("#dataset1").getItems(0, $w("#dataset1").getTotalCount())
        .then( (result) => {
 let items = result.items;
 let totalCount = result.totalCount;
 let firstFilteredItem = items[0]
 let lastFilteredItem = items[totalCount]

            console.log(result)
            console.log(totalCount)
            console.log(firstFilteredItem)
            console.log(lastFilteredItem)
        })
    })
}

Take a look at the CONSOLE-LOGs (Press F-12 in your google-chrome-browser and go to CONSOLE, or look at teconsole in the “Preview-Mode” in your Wix-Editor).

What do you get? (You should get the FILTERED-DATA!)

EDIT:


So in your case, it would be something like this here…

function search() {
 let filter = wixData.filter();
 let filterCheckbox1 = $w("#checkbox1").checked;
 let filterCheckbox2 = $w("#checkbox2").checked;

 if (filterCheckbox1 ) {filter = filter.eq("boolean1", true);}
 if (filterCheckbox2 ) {filter = filter.eq("boolean2", true);}
 
    $w('#dataset1').setFilter(filter)  
    show_filterResults() 
})

function show_results (parameter) {
    $w("#dataset1").onReady( () => {       
        $w("#dataset1").getItems(0, $w("#dataset1").getTotalCount())
        .then( (result) => {
 let items = result.items;
 let totalCount = result.totalCount;
 let firstFilteredItem = items[0]
 let lastFilteredItem = items[totalCount]

            console.log(result)
            console.log(totalCount)
            console.log(firstFilteredItem)
            console.log(lastFilteredItem)
        })
    })
}

EDIT: Sorry there was still a little bug in my code…


let lastFilteredItem = items[totalCount] <<<--- BUGGY

let lastFilteredItem = items[totalCount-1] <<<--- works!

Here the whole code one more time…

export function button4_click(event) {show_results(), $w('#BOXfilterresults').show('FadeIn')}


function show_results (parameter) {
    $w("#dataset1").onReady( () => {    
        $w("#dataset1").getItems(0, $w("#dataset1").getTotalCount())
 
        .then( (result) => {
 let items = result.items
 let totalCount = result.items.length
 let firstFilteredItem = items[0]
 let lastFilteredItem = items[totalCount-1]
 
            console.log(result)
            console.log(totalCount)
            console.log(firstFilteredItem)
            console.log(lastFilteredItem)

            $w('#TXTtotalcount').text = totalCount.toString()
            $w('#TXTfirstitem').text = firstFilteredItem.title.toString()
            $w('#TXTlastitem').text = lastFilteredItem.title.toString()
        })        
    })
}

You can see this CODE working here in this example. I have added this function into the FILTER-example.

https://russian-dima.wixsite.com/meinewebsite/blank-3