Filtering on smart collections

Hey everyone!

I’m trying to implement filtering on a smart collection I have created. I currently enabled the filtering on every fields in that collection, and I can now add filters. However, the filters are not applied directly.

I suppose I have to manually implement the filtering in my get request.

In that very get request, when I console.log(req.query);, I get the following:

{
  fields: {
    bookings_recap: 'id,first_name,last_name,instagram,restaurant,city,booked,paid,table_date,seats,status,tipped'
  },
  filters: '{"aggregator":"and","conditions":[{"field":"city","operator":"equal","value":"Paris"},{"field":"status","operator":"equal","value":"confirmed"}]}',
  page: { number: '1', size: '15' },
  searchExtended: '0',
  timezone: 'Europe/Paris'
}

Do any of you know how I can transform the filters to SQL WHERE conditions?

Thanks.

Hi @daweido ,

Thanks for interest in Forest.
Can you please share your project name? And also the smart collection name.
Is the smart-collection working (except for filtering) ?

Also, did you notice than smart collections are mainly for externals data sources (not your database)? If data comes from your database, native collections are prefered.

Best

Hey @Sliman_Medini,

Thanks for replying.

My project name is Lords and the smart collection name is “Bookings Recap”.

My smart collection is working correctly, getting the correct data and all. But I can’t get the filtering to work.

I did notice that smart collection were mainly used for external data. However, I wanted to use this collection as a mix of several models, used as a reporting table. How can I create such a native collection? I can’t seem to find any mention of a native collection on the link you gave me.

Thanks, David

Ok,

In this case, you can create a view or a materialized view inside your database.
After that, you can create a native collection based on this view and it should work without any manual coding.

Regards

1 Like

Ok, thanks! I will try that out and let you know!

1 Like

Few docs about this.

Regards

Thank you very much!

This will greatly help me.

Btw, do you know if there is a way of adding custom items to the bottom of a table, e.g where there is the count number and page numbers?

This would be to add KPI such as totals.

Regards

I appreciate that it helps.

For now, I am afraid the pagination zone is “hard-coded”. But I am opened to create a feature request because the idea looks good.

Can you please elaborate on the need? For example when/how the custom item should be calculated/retrieved, etc.

No problem.

Basically, it would be adding the possibility of adding some custom KPIs on models in the pagination section.

I have seen that the page number and count number is part of the request coming in, and the response we send back.

It could be some kind of meta data as it is for pagination and counting, for example.

Or even in the model declaration, if there is a way of adding custom footer indicators.

Concerning the calculation, retrieval, declaration, it would be user defined and only printing the array of custom KPIs in that very area.

Hope this is clear enough for you!

It’s crystal clear.
This was added to our product board.

Thank you very much!

I have just been able to implement the model using the MySQL View you told me to use. The filtering is now working correctly!

Thanks!

Best regards