Is it possible to filter entries based on entry table field values?












2















I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.



First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.



Second: I would like to be able to display these values so that they are in an ascending order.










share|improve this question























  • I think you will need to be more specific, perhaps give a code example?

    – Roi Agneta
    Dec 31 '18 at 20:20











  • @RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.

    – Aleks P
    Dec 31 '18 at 20:32


















2















I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.



First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.



Second: I would like to be able to display these values so that they are in an ascending order.










share|improve this question























  • I think you will need to be more specific, perhaps give a code example?

    – Roi Agneta
    Dec 31 '18 at 20:20











  • @RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.

    – Aleks P
    Dec 31 '18 at 20:32
















2












2








2








I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.



First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.



Second: I would like to be able to display these values so that they are in an ascending order.










share|improve this question














I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.



First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.



Second: I would like to be able to display these values so that they are in an ascending order.







craft3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 19:26









Aleks PAleks P

184




184













  • I think you will need to be more specific, perhaps give a code example?

    – Roi Agneta
    Dec 31 '18 at 20:20











  • @RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.

    – Aleks P
    Dec 31 '18 at 20:32





















  • I think you will need to be more specific, perhaps give a code example?

    – Roi Agneta
    Dec 31 '18 at 20:20











  • @RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.

    – Aleks P
    Dec 31 '18 at 20:32



















I think you will need to be more specific, perhaps give a code example?

– Roi Agneta
Dec 31 '18 at 20:20





I think you will need to be more specific, perhaps give a code example?

– Roi Agneta
Dec 31 '18 at 20:20













@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.

– Aleks P
Dec 31 '18 at 20:32







@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.

– Aleks P
Dec 31 '18 at 20:32












1 Answer
1






active

oldest

votes


















2














OK, one possible way is the use the value of the colour field in an if statement, something this:



{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
<li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}


In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit



You could also do it with JavaScript, but that is nasty.



Here is the complete code using an Array to sort by the age field:



{% set tableBlock =  %}
{% set tableRow = %}

{% for row in entry.myTableField %}
{% if row.colour == "blue" %}

{% set tableRow = {
'age' : row.age,
'colour' : row.colour,
'provider' : row.provider
} %}
{% set tableBlock = tableBlock|merge([tableRow]) %}
{% endif %}

{% endfor %}

{% for row in tableBlock|sort %}
  • {{row.age}} {{row.colour}} {{row.provider}}

  • {% endfor %}


    For some reason the code block formatting is not working...






    share|improve this answer


























    • Glad to be of help!

      – Roi Agneta
      Jan 1 at 20:44











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "563"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f28976%2fis-it-possible-to-filter-entries-based-on-entry-table-field-values%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    OK, one possible way is the use the value of the colour field in an if statement, something this:



    {# list rows that have "blue" in the colour field #}
    {% for row in table.fieldName %}
    {% if row.colour == 'blue' %} // probably best to make "blue" a variable
    <li>{{ row.age }} - {{ row.provider }} - etc.</li>
    {% endif %}


    In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit



    You could also do it with JavaScript, but that is nasty.



    Here is the complete code using an Array to sort by the age field:



    {% set tableBlock =  %}
    {% set tableRow = %}

    {% for row in entry.myTableField %}
    {% if row.colour == "blue" %}

    {% set tableRow = {
    'age' : row.age,
    'colour' : row.colour,
    'provider' : row.provider
    } %}
    {% set tableBlock = tableBlock|merge([tableRow]) %}
    {% endif %}

    {% endfor %}

    {% for row in tableBlock|sort %}
  • {{row.age}} {{row.colour}} {{row.provider}}

  • {% endfor %}


    For some reason the code block formatting is not working...






    share|improve this answer


























    • Glad to be of help!

      – Roi Agneta
      Jan 1 at 20:44
















    2














    OK, one possible way is the use the value of the colour field in an if statement, something this:



    {# list rows that have "blue" in the colour field #}
    {% for row in table.fieldName %}
    {% if row.colour == 'blue' %} // probably best to make "blue" a variable
    <li>{{ row.age }} - {{ row.provider }} - etc.</li>
    {% endif %}


    In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit



    You could also do it with JavaScript, but that is nasty.



    Here is the complete code using an Array to sort by the age field:



    {% set tableBlock =  %}
    {% set tableRow = %}

    {% for row in entry.myTableField %}
    {% if row.colour == "blue" %}

    {% set tableRow = {
    'age' : row.age,
    'colour' : row.colour,
    'provider' : row.provider
    } %}
    {% set tableBlock = tableBlock|merge([tableRow]) %}
    {% endif %}

    {% endfor %}

    {% for row in tableBlock|sort %}
  • {{row.age}} {{row.colour}} {{row.provider}}

  • {% endfor %}


    For some reason the code block formatting is not working...






    share|improve this answer


























    • Glad to be of help!

      – Roi Agneta
      Jan 1 at 20:44














    2












    2








    2







    OK, one possible way is the use the value of the colour field in an if statement, something this:



    {# list rows that have "blue" in the colour field #}
    {% for row in table.fieldName %}
    {% if row.colour == 'blue' %} // probably best to make "blue" a variable
    <li>{{ row.age }} - {{ row.provider }} - etc.</li>
    {% endif %}


    In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit



    You could also do it with JavaScript, but that is nasty.



    Here is the complete code using an Array to sort by the age field:



    {% set tableBlock =  %}
    {% set tableRow = %}

    {% for row in entry.myTableField %}
    {% if row.colour == "blue" %}

    {% set tableRow = {
    'age' : row.age,
    'colour' : row.colour,
    'provider' : row.provider
    } %}
    {% set tableBlock = tableBlock|merge([tableRow]) %}
    {% endif %}

    {% endfor %}

    {% for row in tableBlock|sort %}
  • {{row.age}} {{row.colour}} {{row.provider}}

  • {% endfor %}


    For some reason the code block formatting is not working...






    share|improve this answer















    OK, one possible way is the use the value of the colour field in an if statement, something this:



    {# list rows that have "blue" in the colour field #}
    {% for row in table.fieldName %}
    {% if row.colour == 'blue' %} // probably best to make "blue" a variable
    <li>{{ row.age }} - {{ row.provider }} - etc.</li>
    {% endif %}


    In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit



    You could also do it with JavaScript, but that is nasty.



    Here is the complete code using an Array to sort by the age field:



    {% set tableBlock =  %}
    {% set tableRow = %}

    {% for row in entry.myTableField %}
    {% if row.colour == "blue" %}

    {% set tableRow = {
    'age' : row.age,
    'colour' : row.colour,
    'provider' : row.provider
    } %}
    {% set tableBlock = tableBlock|merge([tableRow]) %}
    {% endif %}

    {% endfor %}

    {% for row in tableBlock|sort %}
  • {{row.age}} {{row.colour}} {{row.provider}}

  • {% endfor %}


    For some reason the code block formatting is not working...







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 31 '18 at 21:33

























    answered Dec 31 '18 at 20:53









    Roi AgnetaRoi Agneta

    7912617




    7912617













    • Glad to be of help!

      – Roi Agneta
      Jan 1 at 20:44



















    • Glad to be of help!

      – Roi Agneta
      Jan 1 at 20:44

















    Glad to be of help!

    – Roi Agneta
    Jan 1 at 20:44





    Glad to be of help!

    – Roi Agneta
    Jan 1 at 20:44


















    draft saved

    draft discarded




















































    Thanks for contributing an answer to Craft CMS Stack Exchange!


    • Please be sure to answer the question. Provide details and share your research!

    But avoid



    • Asking for help, clarification, or responding to other answers.

    • Making statements based on opinion; back them up with references or personal experience.


    To learn more, see our tips on writing great answers.




    draft saved


    draft discarded














    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f28976%2fis-it-possible-to-filter-entries-based-on-entry-table-field-values%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown





















































    Required, but never shown














    Required, but never shown












    Required, but never shown







    Required, but never shown

































    Required, but never shown














    Required, but never shown












    Required, but never shown







    Required, but never shown







    Popular posts from this blog

    To store a contact into the json file from server.js file using a class in NodeJS

    Redirect URL with Chrome Remote Debugging Android Devices

    Dieringhausen