{"id":155,"date":"2009-10-24T11:12:59","date_gmt":"2009-10-24T11:12:59","guid":{"rendered":""},"modified":"2009-10-24T11:12:59","modified_gmt":"2009-10-24T11:12:59","slug":"faq-how-to-add-sort-items-drop-buttons-i","status":"publish","type":"post","link":"http:\/\/www.icetips.com\/blog_wp\/2009\/10\/24\/faq-how-to-add-sort-items-drop-buttons-i\/","title":{"rendered":"FAQ:  How to add\/sort items Drop Buttons items in PowerToolbar"},"content":{"rendered":"<p>One of my customers contacted me couple of days ago to ask if it was possible to sort items in a drop button, when the items are created at runtime.  Since the items are stored in a queue I figured it would be fairly easy.  <\/p>\n<div style=\"border: 1px solid gray;padding: 2px;background:#FBFFE8;margin-bottom:10px\">\n<pre>\r\n Toolbar1.DeleteItems(ID1_Name)\r\n\r\n Toolbar1.AddDropItem(ID1_Name,'Arnor','ok_16.ico',1)\r\n Toolbar1.AddDropItem(ID1_Name,'Robert','ok_16.ico',2)\r\n Toolbar1.AddDropItem(ID1_Name,'Monica','ok_16.ico',3)\r\n Toolbar1.AddDropItem(ID1_Name,'Ana Maria','ok_16.ico',4)\r\n Toolbar1.AddDropItem(ID1_Name,'Ivan','ok_16.ico',5)\r\n\r\n Sort(Toolbar1.BandQ.ControlQ.pDropButton.ItemQ,|\r\n      Toolbar1.BandQ.ControlQ.pDropButton.ItemQ.szTxt)\r\n !! Reset the ItemIDs after sorting the queue.\r\n Loop I# = 1 To Records(Toolbar1.BandQ.ControlQ.pDropButton.ItemQ)\r\n   Get(Toolbar1.BandQ.ControlQ.pDropButton.ItemQ,I#)\r\n   Toolbar1.BandQ.ControlQ.pDropButton.ItemQ.ItemID = I#\r\n   Put(Toolbar1.BandQ.ControlQ.pDropButton.ItemQ)\r\n End\r\n Display()\r\n<\/pre>\n<\/div>\n<p>Note that this will not work properly if you have separators in the drop items.  If you want to do that, I would suggest to add the item text entries to a queue and sort them before you add them to the drop button.  Something like this might work:<\/p>\n<div style=\"border: 1px solid gray;padding: 2px;background:#FBFFE8;margin-bottom:10px\">\n<pre>\r\nAddDropButtonItems         ROUTINE\r\n Data\r\nQ   Queue\r\nT     CString(256) !! Item text\r\nSF    Byte         !! Separator Follows\r\n    End\r\n Code\r\n Q.T = 'Arnor' ;     Q.SF = False; Add(Q)\r\n Q.T = 'Robert' ;    Q.SF = True;  Add(Q)\r\n Q.T = 'Monica' ;    Q.SF = False; Add(Q)\r\n Q.T = 'Ana Maria' ; Q.SF = False; Add(Q)\r\n Q.T = 'Ivan' ;      Q.SF = False; Add(Q)\r\n Sort(Q,Q.T)\r\n Toolbar1.DeleteItems(ID1_Name)\r\n Loop X# = 1 To Records(Q)\r\n   Get(Q,X#)\r\n   Toolbar1.AddDropItem(ID1_Name,Q.T,'ok_16.ico',1)\r\n   If Q.SF = True !! Add Separator\r\n     Toolbar1.AddDropItem(ID1_Name,'-','ok_16.ico',1)\r\n   End\r\n End\r\n\r\n Display()\r\n<\/pre>\n<\/div>\n<p>This should be able to handle sorted list with separators.  I'm planning to add a method to sort the items alphabetically and I think I can make it handle the separators correctly too.  The method I describe here is a bit more flexible as it gives you full control over how the items are arranged.  <\/p>\n<p>Arnor Baldvinsson<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_155\" class=\"pvc_stats all  \" data-element-id=\"155\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"http:\/\/www.icetips.com\/blog_wp\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of my customers contacted me couple of days ago to ask if it was possible to sort items in a drop button, when the items are created at runtime. Since the items are stored in a queue I figured it would be fairly easy. Toolbar1.DeleteItems(ID1_Name) Toolbar1.AddDropItem(ID1_Name,'Arnor','ok_16.ico',1) Toolbar1.AddDropItem(ID1_Name,'Robert','ok_16.ico',2) Toolbar1.AddDropItem(ID1_Name,'Monica','ok_16.ico',3) Toolbar1.AddDropItem(ID1_Name,'Ana Maria','ok_16.ico',4) Toolbar1.AddDropItem(ID1_Name,'Ivan','ok_16.ico',5) Sort(Toolbar1.BandQ.ControlQ.pDropButton.ItemQ,| Toolbar1.BandQ.ControlQ.pDropButton.ItemQ.szTxt) !! <a href=\"http:\/\/www.icetips.com\/blog_wp\/2009\/10\/24\/faq-how-to-add-sort-items-drop-buttons-i\/\" class=\"more-link\">...continue reading <span class=\"screen-reader-text\">FAQ:  How to add\/sort items Drop Buttons items in PowerToolbar<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_155\" class=\"pvc_stats all  \" data-element-id=\"155\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"http:\/\/www.icetips.com\/blog_wp\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[8,4,5],"tags":[],"class_list":["post-155","post","type-post","status-publish","format-standard","hentry","category-faq","category-products","category-technical"],"_links":{"self":[{"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/posts\/155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/comments?post=155"}],"version-history":[{"count":0,"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.icetips.com\/blog_wp\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}