SaaS CMS has officially launched! Learn more now.

Ha Bui
Jun 10, 2021
  2517
(1 votes)

DnD support for PropertyList<T>

Hi all,

As you might know then PropertyList<T> is very powerfull. It is help us to easy to manage and organize a list of complex property data but the limitation as I am facing with is that it is not official support sorting via drag and drop (or atleast I don't know how to turn it on - although take hour to googling).

Drag and drop not working on product | Episerver Developer Commun

Then I digged a bit with javascript solution as below then its worked: (I am assumming that you already know about how to create your module via module.config, create your custom editor and map it to your property list property)

So here is our code: SortableCollectionEditor.js

define([
    // dojo
    "dojo/_base/array",
    "dojo/_base/declare",
    "dojo/_base/lang",
    "dojo/aspect",
    "dojo/dom-class",
    "dojo/dom-style",
    "dojo/topic",

    // EPi Framework
    "epi/shell/widget/_FocusableMixin",
    "epi/shell/dnd/Target",


    // epi cms
    "epi-cms/contentediting/editors/CollectionEditor",
    "epi-cms/contentediting/editors/_TextWithActionLinksMixin",

    // epi commerce
    "epi-ecf-ui/contentediting/editors/_GridWithDropContainerMixin"
],
    function (
        //dojo
        array,
        declare,
        lang,
        aspect,
        domClass,
        domStyle,
        topic,

        // EPi Framework
        _FocusableMixin,
        Target,

        // epi cms
        CollectionEditor,
        _TextWithActionLinksMixin,

        // epi commerce
        _GridWithDropContainerMixin,
    ) {
        return declare([CollectionEditor, _GridWithDropContainerMixin, _FocusableMixin], {
            // module:
            //      app/editors/sortablecollectioneditor
            // summary:
            //      Editor widget for support propertylist dnd 

            resources: { "drophere": "You can drop {content} here", "actions": { "content": "content" } },

            postMixInProperties: function () {
                // summary:
                //      Post mix in properties initialization.
                // description:
                //      Fullfills properties that needed to start up the widget.
                // tags:
                //      protected

                this.inherited(arguments);

                this.gridSettings.dndParams = lang.mixin(this.gridSettings.dndParams, {
                    _checkAcceptanceForItems: function (items, acceptedTypes) {
                        var types = array.map(items, function (item) {
                            return item.data.typeIdentifier;
                        });

                        var flag = false;
                        for (var j = 0; j < types.length; ++j) {
                            if (types[j] in acceptedTypes) {
                                flag = !!acceptedTypes[types[j]];
                                break;
                            }
                        }
                        return flag;
                    }
                });
            }
        });
    });

Hope that help!

Ha Bui

Jun 10, 2021

Comments

Scott Reed
Scott Reed Jun 10, 2021 08:23 AM

Is this just because the modal background is greyed out? I did a blog about something similar a while ago using CSS https://world.episerver.com/blogs/scott-reed/dates/2018/3/making-drag-and-drop-pagesmedia-work-with-the-ilist/

Ha Bui
Ha Bui Jun 10, 2021 08:29 AM

Hi Scott, actually the default one CollectionEditor (epi-cms/contentediting/editors/CollectionEditor) did not support this.

Scott Reed
Scott Reed Jun 10, 2021 08:32 AM

Hmmmn, strange I know when I posted the blog and removed the CSS overlay I could drag and drop blocks/media and such in the PropertyList at least at the time of writing

Ha Bui
Ha Bui Jun 10, 2021 08:35 AM

Ah, it is different, my workaround is for change item sort order inside the list (using DnD instead of move up/down, very anoying when you have a long list)

And by the way, I'm talking about generic one (CollectionEditor) but not CommerceMediaCollectionEditor.

Scott Reed
Scott Reed Jun 10, 2021 09:41 AM

Yes I'm just referring to a PropertyList not anything commerce. Okay I see, sort order, I thought you meant drag and drop as in from other panes. My bad :p

Tomasz Madeyski
Tomasz Madeyski May 23, 2022 09:08 AM

Do you have a version working in a setup without Commerce? (in my solution epi-ecf-ui/contentediting/editors/_GridWithDropContainerMixin is missing)

Please login to comment.
Latest blogs
Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024

GetNextSegment with empty Remaining causing fuzzes

Optimizely CMS offers you to create partial routers. This concept allows you display content differently depending on the routed content in the URL...

David Drouin-Prince | Jul 8, 2024 | Syndicated blog

Product Listing Page - using Graph

Optimizely Graph makes it possible to query your data in an advanced way, by using GraphQL. Querying data, using facets and search phrases, is very...

Jonas Bergqvist | Jul 5, 2024