We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21671
    • 244 Posts
    Anyone up to the task? It seems like it would make layout inside the manager so much easier for the end user. One would put the chunks in a left sidebar catagory and a right sidebar catagory. Then the chunks would dynamically populate the lists and then the end user would put checks nextto whichever chunks they want on a page by page basis and then they could manually sort the chunks in whatever order they want. That is just my vision.
      • 13388
      • 33 Posts
      While this topic is somewhat old, it basically describes exactly what I’m trying to create.

      Has there been any update for this functionality? It just seems like a no brainer in terms of admin delight. wink
        • 13177
        • 1 Posts
        Well, I think I managed to create a solution for the custom sorting.

        I created a custom TV Input, which puts the list of chunks in a table. The rows are draggable; this way one can apply a custom order! Unfortunately I couldn’t manage to keep the order while editing a resource (everything is beeing set back to default. But can be reordered).

        Here’s the tpl code (and I might warn you: i’m no pro! so the code could be quite messy):

        <div id="tv{$tv->id}-cb"></div>
        <script type="text/javascript">
        // <![CDATA[
        {literal}
            var reader{/literal}{$tv->id}{literal} = new Ext.data.ArrayReader({}, [
                {name: 'id'},
                {name: 'name'},
                {name: 'value'},
                {name: 'label'},
                {name: 'checked'}
            ]);
            var store{/literal}{$tv->id}{literal} = new Ext.data.Store({
                autoDestroy: true,
                reader: reader{/literal}{$tv->id}{literal},
                data: [{/literal}
                    {foreach from=$opts item=item key=k name=cbs}
                        {literal}[{/literal}
                        'tv{$tv->id}-{$k}',
                        'tv{$tv->id}[]',
                        '{$item.value}',
                        '{$item.text|escape:"javascript"}',
                        '<center><input id="tv{$tv->id}-{$k}" type="checkbox" value="{$item.value}" name="tv{$tv->id}[]" checked="{if $item.checked}true{else}false{/if}" /></center>'
                        {literal}],{/literal}
                    {/foreach}
                {literal}]
            });
            var grid{/literal}{$tv->id}{literal} = new Ext.grid.GridPanel({
                store: store{/literal}{$tv->id}{literal},
                colModel: new Ext.grid.ColumnModel({
                    defaults: {
                        width: 125,
                        sortable: false
                    },
                    columns: [
                        {id: 'label', header: 'Name', dataIndex: 'label'},
                        {id: 'checked', header: 'Aktiviert?', dataIndex: 'checked'}
                    ]
                }),
                viewConfig: {
                    forceFit: true
                },
                width: 350,
                height: 250,
                frame: true,
                enableDragDrop: true,
                ddGroup: 'zusatzInhalteGroup',
                ddText: 'Sortieren',
                renderTo: {/literal}'tv{$tv->id}-cb'{literal}
            });
            var ddrow{/literal}{$tv->id}{literal} = new Ext.dd.DropTarget(
                grid{/literal}{$tv->id}{literal}.getView().mainBody, {
                ddGroup: 'zusatzInhalteGroup',
                notifyDrop: function(dd, e, data) {
                    var sm = grid{/literal}{$tv->id}{literal}.getSelectionModel();
                    var rows = sm.getSelections();
                    var cindex = dd.getDragData(e).rowIndex;
                    var store = grid{/literal}{$tv->id}{literal}.getStore();
                    if (sm.hasSelection()) {
                        for (i = 0; i < rows.length; i ++) {
                            store.remove(store.getById(rows[i].id));
                            store.insert(cindex,rows[i]);
                        }
                        sm.selectRecords(rows);
                    }
                }
            });
        {/literal}
        // ]]>
        </script>​


        The php-code (the connector ... i think it is called) is the same as the modx-default for checkbox.
          • 10226
          • 412 Posts
          I have always named my chunks like below, to give them a pseudo-weight.

          0-always-first-chunk
          00-top-chunk
          10-another
          99-is-last

          This way you can come back and add chunk 05-whatever or 98-first-to-last if needed.
            • 20002
            • 22 Posts
            Enter 1.2.3 etc in each chunk description. Update getchunks snippet with below code.


            <?php
            /* Get the chunk objects */
            $c = $modx->newQuery('modChunk');
            $c->leftJoin('modCategory','Category');
            $c->where(array(
            'Category.category' => $category,
            ));

            /* Sort the chunk by Description*/

            $c->sortby('description','ASC');
            $c->limit(10);
            $resources = $modx->getCollection('modResource',$c);




            $chunkArray = $modx->getCollection('modChunk',$c);

            $chunkNames=array();

            /* Put the chunk names into the array */

            foreach($chunkArray as $chunk) {
            $chunkNames[] = $chunk->get('name');
            }

            /* Format the chunknames as a delimited string for the TV */
            $l_chunks = implode("||",$chunkNames);
            return $l_chunks;
              PSD to Modx Templates & Custom Modx Development
              http://modxexpert.com

              Twitter: modxexpert
              • 21671
              • 244 Posts
              Hey All,

              Well after a long ahul I've implemented this: You can see another forum post on how to implement it at:
              https://forums.modx.com/thread/72824/sortable-sidebar-a-cynch-with-customsort-sidebar-chunks#dis-post-405544

              I have a tutorial at : http://bit.ly/zfr4WE

              and a video tutorial at http://bit.ly/wRxqkw

              I hope you dig it!

              -Noah