Crocoblock / suggestions

The suggestions for CrocoBlock project
191 stars 78 forks source link

JetFilters and JetEngine Rest API module #7463

Open Balzactorino opened 3 months ago

Balzactorino commented 3 months ago

I do not know whether any of you have already come across the problem of filtering the results obtained through the Rest API module. Currently it does not seem to be available or working, is there a way to filter the results? Because I think the Rest API module is used to display a large number of results, and I don't think it's useful to waste the user's time searching for what they need without having the ability to filter the results obtained. Thanks to all.

Crocoblock commented 3 months ago

Hi @Balzactorino

In the most recent updates of JetEngine and JetSmartFilters, we have introduced the Plain Query Variable. Kindly note that it only works for REST API endpoint that allow querying and filtering, so don't forget to check if you endpoint allows that and what parameters you can query by.

Firstly, you need to create a filter where options have the same values as the values of your REST API fields. They should be identical so that the filter can compare the value of the filter option to the value of the item from your endpoint.

For example, I have an endpoint that returns a list of countries, and this endpoint can be queried by the country name https://prnt.sc/ObWKxdFqbLLx I can create a filter and populate the options manually: https://prnt.sc/OR2spfVjCC6O Or I can create a REST API query: https://prnt.sc/ObWKxdFqbLLx and populate filter options from it: https://prnt.sc/iuhYaeV4LiEF

Then, apply the Plain Query Variable and insert a random string: https://prnt.sc/qB-v79F3i2kq

Create a new REST API query. This time, add a query by the needed parameter (in my example, the name of the country): https://prnt.sc/K2FF0ceA0Rv6 In the Value, insert the JetSmartFilters macro and type in the same Plain Query Variable: https://prnt.sc/P351DCuwDHmQ

The final step is to create a Listing Template and select a source for it from the second custom query: https://prnt.sc/VJeZ1ixjKQQ3

Lastly, display the listing with the Listing Grid widget on the needed page and display the created filter. The filter now passes the value of the selected option to the REST API query, and in this way, the 'filtering' happens.

Balzactorino commented 3 months ago

Thanks a lot for your reply!!! I have this situation:

Screenshot 2024-04-05 alle 13 58 16

I have to rebuild this on the news website I'm building. Actually it works by usign a REST API end points. Whit the method you described is possible to use five different type of search filters (by city, by target, by name...)?

Thanks again!

Balzactorino commented 2 months ago

Hi guys, I tried but it doesn't works! I don't know where I'm wrong! :(

artydub commented 1 month ago

this method also works for only one filter (

mauro500designs commented 1 month ago

The solution to this will be to have a functionality to allow the Endpoint to be saved and syncronized to the DB. For example, getting all data save within the DB in a new table ex. wp_jet_myendpoint so you can filter and manipulate all the data without any issues or delays.

Having this, will solve HUGE performance issues, and you will be able to create specific queries to get the data as you want. Bad news, this is not a functionality on jetengine.

I posted a feature request for this, so we can have a functionality to store and sync (every x minutes, days, manual sync, etc) the Endpoint with the DB.

We are working internally for something like this, but takes time to develop...

Screenshot 2024-05-10 at 8 31 41 PM

If you like this, upvote this post and comment to have this functionality built from Crocoblock!https://github.com/Crocoblock/suggestions/issues/7494