How to show all items while filters are unchecked

Hello,
I’m creating a page with differents publications. Users can check a multicheckbox to filter a category of publications. I wrote the code for it and it works properly. However, when no category is checked, I would like all publications appear on the page… but I can’t find the right code… Could someone help me to find the right solution please ? Here is my code :

import wixData from ‘wix-data’ ;
$w.onReady( function () {
filterView();
$w( “#checkboxGroup1” ).onChange( (event, $w) => {
filterView();
});
});

function filterView(){
var categoriesFilter = $w( “#checkboxGroup1” ).value
console.log( ‘categories’ ,categoriesFilter);
$w( “#publications” ).setFilter(wixData.filter()
.hasSome( “categories” ,categoriesFilter)
)

.then( () => { 

let count = $w( “#publications” ).getTotalCount();
if (count === 0 ){
$w( “#repeater1” ).hide();
} else {
$w( “#repeater1” ).show();
}
} )
. catch ( (err) => {
console.log(err);
} );
}

For more precisions :

  • my dataset name is : publications

  • publications are in a repeater called “repeater1”

  • the dataset field filtered is : categories

  • and the mutlicheckbox is “checkboxGroup1”

Thanks a lot for your help !! :slightly_smiling_face:

reset a filter …

$w("#myDataset").setFilter( wixData.filter());

Wow !! Yes !! It was so simple ^^… Thank you so much Russian-dima ! It works… slow, but it works :grin:
For those who are interested, here is the complete code working properly :

import wixData from ‘wix-data’ ;
$w.onReady( function () {
filterView();
$w( “#checkboxGroup1” ).onChange( (event, $w) => {
filterView();
});
});

function filterView(){
var categoriesFilter = $w( “#checkboxGroup1” ).value
console.log( ‘categories’ ,categoriesFilter);
$w( “#publications” ).setFilter(wixData.filter()
.hasSome( “categories” ,categoriesFilter)
)
.then( () => {
let count = $w( “#publications” ).getTotalCount();
if (count === 0 ){
$w( “#publications” ).setFilter(wixData.filter());
}
} )
. catch ( (err) => {
console.log(err);
} );
}

@remipommereuil
Well done!
You earned a —> LIKE for sharing ^^ :heart: (your first one)