import wixData from ‘wix-data’ ;
export function search_click(event, $w) { //Button onClick event
$w( “#buildingdataset” ).setFilter(wixData.filter() //Set dataset to filter
.contains( "location" , $w( "#locationDropdown" ).value) // field key and dropdown
.between( "typicalFloorPlate" , parseFloat($w( "#dropdown4" ).value), parseFloat($w( "#dropdown3" ).value))) // field key and dropdown
.then((results) => {
console.log( "Dataset is filtered" );
$w( "buildingdataset" ).data = results.items;
}). **catch** ((err) => {
console.log(err);
});
$w( "buildingdataset" ).expand();
}
$w.onReady( function () {
$w( '#clear' ).onClick(() => {
$w( "#dropdown4" ).value = **undefined**
$w( "#buildingdataset" ).setFilter(wixData.filter()
.eq( 'typicalFloorPlate' , location))
});
$w( '#clear' ).onClick(() => {
$w( "#dropdown3" ).value = **undefined**
$w( "#buildingdataset" ).setFilter(wixData.filter()
.eq( 'typicalFloorPlate' , location))
});
$w( '#clear' ).onClick(() => {
$w( "#locationDropdown" ).value = **undefined**
$w( "#buildingdataset" ).setFilter(wixData.filter()
.eq( 'location' , location))
});
});
here’s our code, the page is working. It filters the buildings but it keeps on saying that line 16 is wrong. Can someone pls help me to know whats wrong about this code?? thank you!!
Are you trying to expand a —DATASET ???
we’re trying to filter the area size of each buildings for example from 100 - 500 sqm yet it’s filtering but there’s an error when we are in the preview mode. I already fixed the problem but the other problem is, when we publish it, its not working but in preview mode its clearly working
@guintoallona
Yes, i hope you fixed this line here…
$w("buildingdataset").expand();
Because you can’t expand a DATASET.
Did you have sunced your SANDBOX with your LIVE-DATABASE ?
This could be the reason why you don’t get anything shown on your LIVE-Site.
@russian-dima I fixed that I wrote $w(“#buildingdataset”).expand();
(I guess it still the .expand, what is the other option rather than using expand coz u said it can’t expand a dataset, to show the filter bldgs?)
Yes it was automatically synced.
@russian-dima
import wixData from ‘wix-data’ ;
export function search_click(event, $w) { //Button onClick event
$w( “#buildingdataset” ).setFilter(wixData.filter() //Set dataset to filter
.contains( "location" , $w( "#locationDropdown" ).value) // field key and dropdown
.between( "typicalFloorPlate" , parseFloat($w( "#dropdown4" ).value), parseFloat($w( "#dropdown3" ).value))) // field key and dropdown
.then((results) => {
console.log( "Dataset is filtered" );
$w( "#repeater" ).data = results;
}). **catch** ((err) => {
console.log(err);
});
$w( "#repeater2" ).expand();
}
export function clear_click(event, $w) {
$w( ‘#clear’ ).onClick(() => {
$w( “#dropdown4” ).value = undefined
$w( “#buildingdataset” ).setFilter(wixData.filter()
.eq( ‘typicalFloorPlate’ , location))
});
$w( '#clear' ).onClick(() => {
$w( "#dropdown3" ).value = **undefined**
$w( "#buildingdataset" ).setFilter(wixData.filter()
.eq( 'typicalFloorPlate' , location))
});
$w( '#clear' ).onClick(() => {
$w( "#locationDropdown" ).value = **undefined**
$w( "#buildingdataset" ).setFilter(wixData.filter()
.eq( 'location' , location))
});
}
here’s our updated codes
@guintoallona
I took a second look onto your CODE → HOUSTEN WE HAVE A PROBLEM
I have tried to give your CODE some structure, although not everything was clear
Try to replace your old with this one and test it.
import wixData from 'wix-data';
$w.onReady(function () {
$w('#clear').onClick(() => {
$w("#locationDropdown").value = undefined
$w("#dropdown3").value = undefined
$w("#dropdown4").value = undefined
$w("#buildingdataset").setFilter(wixData.filter().eq('typicalFloorPlate', location))
$w("#buildingdataset").setFilter(wixData.filter().eq('location', location))
});
$w('#search').onClick(() => {
$w("#buildingdataset").setFilter(wixData.filter()
.contains("location", $w("#locationDropdown").value)
.between("typicalFloorPlate", parseFloat($w("#dropdown4").value), parseFloat($w("#dropdown3").value)))
.then((results) => {console.log("Dataset is filtered");
$w("#repeater").data = results.items;
})
.catch((err) => {
console.log(err);
});
$w("#repeater2").expand();
});
});
@russian-dima hi thank you for your effort its working but it says that the items cannot read property
here :>
@guintoallona
Because you are using the dataset, i would suggest you to connect it also to your dropdowns and to your repeater, than you will need just the following code…
import wixData from 'wix-data';
$w.onReady(function () {
$w('#clear').onClick(() => {
$w("#dropdown1").value = undefined
$w("#dropdown2").value = undefined
$w("#dropdown3").value = undefined
$w("#buildingdataset").setFilter(wixData.filter())
});
$w('#search').onClick(() => {
$w("#buildingdataset").setFilter(wixData.filter()
.contains("firstName", $w("#dropdown1").value)
.contains("lastName", $w("#dropdown2").value)
.contains("nationality", $w("#dropdown3").value))
.catch((err) => {console.log(err);});
$w("#repeater").expand();
});
});
Take a quick look onto this example here…
https://mt2-king.wixsite.com/filter-tool/csv-test
The shown code is working on this site.