{"id":4426,"date":"2023-01-30T15:48:16","date_gmt":"2023-01-30T15:48:16","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4426"},"modified":"2023-01-31T06:12:55","modified_gmt":"2023-01-31T06:12:55","slug":"filtering-gallery-using-radio-button","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4426","title":{"rendered":"Filtering Gallery using Radio Button"},"content":{"rendered":"<p><strong>Requirement<\/strong><br \/>\nImplementing Gallery data filtering using radio button.<\/p>\n<p><strong>Details<\/strong><br \/>\nlet&#8217;s say we have requirement to filter gallery data based on the selection of the radio button like below<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4433 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp1-300x182.png\" alt=\"filterapp1\" width=\"300\" height=\"182\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp1-300x182.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp1-1024x621.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp1-624x378.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp1.png 1331w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>To implement filter, I am using collection here and Dataverse Account entity as data source where I have records of different types (using Relationship Type attribute for customer category) so first let&#8217;s create two collection, one which will hold active accounts and another one where we will store filtered accounts based on the radio selection.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4434 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp2-300x113.png\" alt=\"filterapp2\" width=\"300\" height=\"113\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp2-300x113.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp2-1024x384.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp2-624x234.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp2.png 1181w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now let&#8217;s place a radio button and change it&#8217;s Layout property to Horizontal and set <strong>Items<\/strong> property like below<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4435 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp3-300x76.png\" alt=\"filterapp3\" width=\"300\" height=\"76\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp3-300x76.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp3-1024x259.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp3-624x158.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp3.png 1417w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now let&#8217;s place a gallery control and set our second collection under <strong>Items <\/strong>property<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4436 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp4-300x127.png\" alt=\"filterapp4\" width=\"300\" height=\"127\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp4-300x127.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp4-1024x434.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp4-624x264.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp4.png 1520w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>By default you won&#8217;t see any data in the gallery control, to load data initially we can run <strong>OnStart <\/strong>manually like below<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp5.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4437 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp5-300x119.png\" alt=\"filterapp5\" width=\"300\" height=\"119\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp5-300x119.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp5.png 491w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now let&#8217;s place below expression <strong>Onselect <\/strong>property of radio control<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nIf(\r\n    currentfilter.Selected.Value = 1,\r\n    ClearCollect(\r\n        currentCollects,\r\n        Filter(\r\n            ActiveAccountsCols,\r\n            'Relationship Type' = 'Relationship Type (Accounts)'.Customer\r\n        )\r\n    ),\r\n    currentfilter.Selected.Value = 2,\r\n    ClearCollect(\r\n        currentCollects,\r\n        Filter(\r\n            ActiveAccountsCols,\r\n            'Relationship Type' = 'Relationship Type (Accounts)'.Investor\r\n        )\r\n    ),\r\n    currentfilter.Selected.Value = 3,\r\n    ClearCollect(\r\n        currentCollects,\r\n        Filter(\r\n            ActiveAccountsCols,\r\n            'Relationship Type' = 'Relationship Type (Accounts)'.Partner\r\n        )\r\n    )\r\n)\r\n<\/pre>\n<p>Finally let&#8217;s setup &#8220;Customer&#8221; under the <strong>Default <\/strong>property<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp6.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4438 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp6-300x140.png\" alt=\"filterapp6\" width=\"300\" height=\"140\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp6-300x140.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp6-1024x479.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp6-624x292.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterapp6.png 1457w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now filtering should work like below !<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterresult.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4439 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterresult-300x169.gif\" alt=\"filterresult\" width=\"300\" height=\"169\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterresult-300x169.gif 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterresult-1024x576.gif 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2023\/01\/filterresult-624x351.gif 624w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Summary<\/strong><br \/>\nThis is how we can filter gallery control.<\/p>\n<p>Hope it will help someone !!<br \/>\n<strong>Keep learning and Keep Sharing !!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirement Implementing Gallery data filtering using radio button. Details let&#8217;s say we have requirement to filter gallery data based on the selection of the radio button like below To implement filter, I am using collection here and Dataverse Account entity as data source where I have records of different types (using Relationship Type attribute for customer category) so first let&#8217;s&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4426\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[817,21,402,728],"tags":[1015,1016,1017,1014],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4426"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4426"}],"version-history":[{"count":7,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4426\/revisions"}],"predecessor-version":[{"id":4445,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4426\/revisions\/4445"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}