<p>Table fields in Craft just store their data in a JSON blob in the content table. That means you can't really query them like you would other things, you'd have to load in all of the data, and then filter it out as an array.</p>

<p>While you can certainly do this in Twig, it smacks of a bit too much "business logic" in Twig; so at this point I might be considering one of two options:</p>

<ol>
<li><p>Refactoring it out to a
<a href="https://nystudio107.com/blog/so-you-wanna-make-a-craft-3-plugin" rel="nofollow noreferrer">plugin</a>
or
<a href="https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module" rel="nofollow noreferrer">module</a>
that will do the heavy lifting behind the scenes</p></li>
<li><p>Changing the schema I'm using to store the data in something that
<em>can</em> be queried, such as moving the data into entries or a matrix block or perhaps a
<a href="https://github.com/verbb/super-table" rel="nofollow noreferrer">SuperTable</a></p></li>
</ol>

<p>Or if either of these seems like too much work, or you're not storing a whole lot of data in the Table field, then I'd just do it in Twig by looping through all of the rows in the table, and selecting only the ones that meet my criteria.</p>

CC BY-SA 4.0
2018-08-12T19:44:05.767Z
Thanks for the clarification. I have used super tables before, great plugin! Do you know a good example or an article about filtering with supertables?
RvdB
CC BY-SA 4.0
2018-08-11T17:42:17.907Z
2018-08-11T17:42:17.907Z
andrew.welch
<p>I am trying to build a query to fetch some entries which I want filter on a table field between multiple values. The table field is "filterTestWidth" and has 1 col named "size" (number type). There are multiple entries with multiple values in col1.</p>

<pre><code>{% set items = craft.entries({
    "section": "catalog",
    "filterTestWidth": [
        "and",
        "&gt; 180",
        "&lt; 190"
    ]
}) %}
</code></pre>

<p>Unfortunate the Craft manual is limited on this subject. Does anyone know a more detailed article about element criteria?</p>

<elementcriteriamodel><table-field>
Element criteria with a table field
# Element criteria with a table field

(Asked by: username_0 on 2018-08-09)

I am trying to build a query to fetch some entries which I want filter on a table field between multiple values. The table field is "filterTestWidth" and has 1 col named "size" (number type). There are multiple entries with multiple values in col1.
{% set items = craft.entries({
    "section": "catalog",
    "filterTestWidth": [
        "and",
        "> 180",
        "< 190"
    ]
}) %}

Unfortunate the Craft manual is limited on this subject. Does anyone know a more detailed article about element criteria?

**Tags:** elementcriteriamodel, table-field

---

## 1 answers

### Answer by username_1 on 2018-08-11. Score: 0 | Accepted answer

Table fields in Craft just store their data in a JSON blob in the content table. That means you can't really query them like you would other things, you'd have to load in all of the data, and then filter it out as an array.

While you can certainly do this in Twig, it smacks of a bit too much "business logic" in Twig; so at this point I might be considering one of two options:

1. Refactoring it out to a
   [plugin](https://nystudio107.com/blog/so-you-wanna-make-a-craft-3-plugin)
   or
   [module](https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module)
   that will do the heavy lifting behind the scenes
2. Changing the schema I'm using to store the data in something that
   *can* be queried, such as moving the data into entries or a matrix block or perhaps a
   [SuperTable](https://github.com/verbb/super-table)

Or if either of these seems like too much work, or you're not storing a whole lot of data in the Table field, then I'd just do it in Twig by looping through all of the rows in the table, and selecting only the ones that meet my criteria.

> **Comments:**
> **username_0**: Thanks for the clarification. I have used super tables before, great plugin! Do you know a good example or an article about filtering with supertables?  

---

