We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22840
    • 1,572 Posts
    Hi All,

    Working on a site where the client has a dropdown to select a page to link to and they would like them sorting alphabetically, this is done within a migx TV as follows:

    Form Tabs
    [
    {"caption":"Box", "fields": [
        {"field":"FBTitle","caption":"Title", "inputTV":"Text"},
        {"field":"FunctionBoxImg","caption":"Image","inputTV":"Image"},
    {"field":"FBLink","caption":"Page Link","inputTV":"ResourceList"}
    ]}
    ] 


    Grid:

    [
    {"header": "Function Box Title", "width": "160", "sortable": "false", "dataIndex": "FBTitle"},
    {"header": "Function Box Image", "width": "160", "sortable": "false", "dataIndex": "FunctionBoxImg"},
    {"header": "Function Box Page Link", "width": "160", "sortable": "false", "dataIndex": "FBLink"}
    ]


    Is there anything I can add to make them sort alphabetically ?

    Thanks

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      instaed of a ResourceList - tv, you can use a simple listbox inputTVtype with @EVAL, @CHUNK or @SELECT - binding.

      Example with @CHUNK - binding:

      {"field":"FBLink","caption":"Page Link","inputTVtype":"listbox","inputOptionValues":"@CHUNK resourcelist_options"}


      the chunk 'resourcelist_options':

      --select a Resource==||
      [[migxLoopCollection?
      &classname=`modResource`
      &tpl=`@CODE:[[+pagetitle]]==[[+id]]`
      &outputSeparator=`||`
      &sortConfig=`[{"sortby":"pagetitle"}]`
      &where=`{"parent":"theParentID"}`
      ]]


      [ed. note: Bruno17 last edited this post 11 years, 9 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22840
        • 1,572 Posts
        Hi Bruno,

        Thanks for the reply,

        Typo in the instructions, the chunk 'resourcelist_optioins': should be the chunk 'resourcelist_options':

        Works like a charm but only listing top level, can I set the container depth as I need to go through 4 levels

        Thanks [ed. note: paulp last edited this post 11 years, 9 months ago.]
        • discuss.answer
          • 4172
          • 5,888 Posts
          you can try this.
          snippet getChildIds:

          <?php
          
          $parent = $modx->getOption('parent',$scriptProperties,0);
          $depth = $modx->getOption('depth',$scriptProperties,10);
          $options['context'] = $modx->getOption('context',$scriptProperties,'web');
          
          $childids = $modx->getChildIds($parent,$depth,$options);
          
          return implode(',',$childids);
          


          then:

          --select a Resource==||
          [[migxLoopCollection?
          &classname=`modResource`
          &tpl=`@CODE:[[+pagetitle]]==[[+id]]`
          &outputSeparator=`||`
          &sortConfig=`[{"sortby":"pagetitle"}]`
          &where=`{"parent:IN":[ [[getChildIds? &depth=`3` &parent=`theParentID`]] ]}`
          ]]


          you could also use getResources or pdoResources

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 22840
            • 1,572 Posts
            Thanks Bruno, spot on as always