# Filtering on smart collections

**URL:** <https://community.forestadmin.com/t/filtering-on-smart-collections/1658>\
**Category:** Help me!\
**Created:** [January 18, 2021, 3:50pm UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658 "2021-01-18T15:50:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![daweido](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/daweido/32/1360_2.png) [@daweido](https://community.forestadmin.com/u/daweido)\
**Post date:** [January 18, 2021, 3:50pm UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/1 "2021-01-18T15:50:02Z")

</div>

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:

```javascript
{
  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.

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [January 19, 2021, 9:25am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/2 "2021-01-19T09:25:40Z")

</div>

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.](https://docs.forestadmin.com/documentation/reference-guide/collections/create-a-smart-collection)

Best

---

<div class="post-metadata">

**Author:** ![daweido](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/daweido/32/1360_2.png) [@daweido](https://community.forestadmin.com/u/daweido)\
**Post date:** [January 19, 2021, 9:31am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/3 "2021-01-19T09:31:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [January 19, 2021, 9:44am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/4 "2021-01-19T09:44:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daweido](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/daweido/32/1360_2.png) [@daweido](https://community.forestadmin.com/u/daweido)\
**Post date:** [January 19, 2021, 9:56am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/5 "2021-01-19T09:56:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [January 19, 2021, 10:04am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/6 "2021-01-19T10:04:43Z")

</div>

[Few docs about this.](https://docs.forestadmin.com/documentation/how-tos/databases/manage-sql-views)

Regards

---

<div class="post-metadata">

**Author:** ![daweido](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/daweido/32/1360_2.png) [@daweido](https://community.forestadmin.com/u/daweido)\
**Post date:** [January 19, 2021, 10:21am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/7 "2021-01-19T10:21:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [January 19, 2021, 10:37am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/8 "2021-01-19T10:37:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![daweido](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/daweido/32/1360_2.png) [@daweido](https://community.forestadmin.com/u/daweido)\
**Post date:** [January 19, 2021, 10:52am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/9 "2021-01-19T10:52:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [January 19, 2021, 11:07am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/10 "2021-01-19T11:07:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daweido](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/daweido/32/1360_2.png) [@daweido](https://community.forestadmin.com/u/daweido)\
**Post date:** [January 19, 2021, 11:23am UTC](https://community.forestadmin.com/t/filtering-on-smart-collections/1658/11 "2021-01-19T11:23:11Z")

</div>

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
