How can I set a fixed element alongside vue draggable list










0















I am trying to display a list of draggable elements using vue-draggable, which are sometimes separated by a fixed element at given position(s).



So far I tried the following approach : creating a different element when needed inside the v-for loop.



<draggable :list="list" class="dragArea" :class="dragArea: true" 
:options="group:'people', draggable: '.drag'" @change="handleChange">
<template v-for="(element, index) in list">
<div class="drag">
element.name
</div>
<div class="nodrag" v-if="index === 2">Fixed element</div>
</template>
</draggable>


However, it is breaking the behavior of my app, as the indexes returned by the onChange event are not what is expected anymore. (You can check a reproduction on this jsfiddle)



Am I doing this wrong ? I also considered using the move prop to disable the dragging ability as suggested here, but the problem remains, because I am using element from outside the draggable list I believe.



In our production usecase, fixed element's index is variable, if that matters.










share|improve this question






















  • So the position of fixed element should not change? or are they just not draggable?

    – Sujil Maharjan
    Nov 13 '18 at 16:04












  • Position of fixed element should not change, there should always be the same number of draggable items before and after it. It will actually represent some kind of a threshold

    – Eddo
    Nov 13 '18 at 16:16











  • Why don't you make two lists? Otherwise the expectation doesn't really make sense. If there are 2 elements before fixed and 2 elements after fixed element --> then you move 1 element from before fixed to after, so, what will be the elements before fixed? an empty string?

    – Sujil Maharjan
    Nov 13 '18 at 16:34











  • Say you have A,B,Fixed,C,D and you move B inbetween C and D, then you should get A,C,Fixed,B,D Ideally I would like Fixed to be just a visual sign completely ignored by the draggable component logic

    – Eddo
    Nov 13 '18 at 16:44






  • 1





    I would listen to some onChange event and just manually move the elements above/below the fixed element. When using something like vue-draggable you have to remember that if it wasn't developed with the functionality you have in mind you're probably gonna have to create it yourself, i.e. moving them "manually" up and down. You can also fork vue-draggable or make a pull request in order to add the functionality so you can keep your code cleaner.

    – Simon Hyll
    Nov 14 '18 at 6:09















0















I am trying to display a list of draggable elements using vue-draggable, which are sometimes separated by a fixed element at given position(s).



So far I tried the following approach : creating a different element when needed inside the v-for loop.



<draggable :list="list" class="dragArea" :class="dragArea: true" 
:options="group:'people', draggable: '.drag'" @change="handleChange">
<template v-for="(element, index) in list">
<div class="drag">
element.name
</div>
<div class="nodrag" v-if="index === 2">Fixed element</div>
</template>
</draggable>


However, it is breaking the behavior of my app, as the indexes returned by the onChange event are not what is expected anymore. (You can check a reproduction on this jsfiddle)



Am I doing this wrong ? I also considered using the move prop to disable the dragging ability as suggested here, but the problem remains, because I am using element from outside the draggable list I believe.



In our production usecase, fixed element's index is variable, if that matters.










share|improve this question






















  • So the position of fixed element should not change? or are they just not draggable?

    – Sujil Maharjan
    Nov 13 '18 at 16:04












  • Position of fixed element should not change, there should always be the same number of draggable items before and after it. It will actually represent some kind of a threshold

    – Eddo
    Nov 13 '18 at 16:16











  • Why don't you make two lists? Otherwise the expectation doesn't really make sense. If there are 2 elements before fixed and 2 elements after fixed element --> then you move 1 element from before fixed to after, so, what will be the elements before fixed? an empty string?

    – Sujil Maharjan
    Nov 13 '18 at 16:34











  • Say you have A,B,Fixed,C,D and you move B inbetween C and D, then you should get A,C,Fixed,B,D Ideally I would like Fixed to be just a visual sign completely ignored by the draggable component logic

    – Eddo
    Nov 13 '18 at 16:44






  • 1





    I would listen to some onChange event and just manually move the elements above/below the fixed element. When using something like vue-draggable you have to remember that if it wasn't developed with the functionality you have in mind you're probably gonna have to create it yourself, i.e. moving them "manually" up and down. You can also fork vue-draggable or make a pull request in order to add the functionality so you can keep your code cleaner.

    – Simon Hyll
    Nov 14 '18 at 6:09













0












0








0








I am trying to display a list of draggable elements using vue-draggable, which are sometimes separated by a fixed element at given position(s).



So far I tried the following approach : creating a different element when needed inside the v-for loop.



<draggable :list="list" class="dragArea" :class="dragArea: true" 
:options="group:'people', draggable: '.drag'" @change="handleChange">
<template v-for="(element, index) in list">
<div class="drag">
element.name
</div>
<div class="nodrag" v-if="index === 2">Fixed element</div>
</template>
</draggable>


However, it is breaking the behavior of my app, as the indexes returned by the onChange event are not what is expected anymore. (You can check a reproduction on this jsfiddle)



Am I doing this wrong ? I also considered using the move prop to disable the dragging ability as suggested here, but the problem remains, because I am using element from outside the draggable list I believe.



In our production usecase, fixed element's index is variable, if that matters.










share|improve this question














I am trying to display a list of draggable elements using vue-draggable, which are sometimes separated by a fixed element at given position(s).



So far I tried the following approach : creating a different element when needed inside the v-for loop.



<draggable :list="list" class="dragArea" :class="dragArea: true" 
:options="group:'people', draggable: '.drag'" @change="handleChange">
<template v-for="(element, index) in list">
<div class="drag">
element.name
</div>
<div class="nodrag" v-if="index === 2">Fixed element</div>
</template>
</draggable>


However, it is breaking the behavior of my app, as the indexes returned by the onChange event are not what is expected anymore. (You can check a reproduction on this jsfiddle)



Am I doing this wrong ? I also considered using the move prop to disable the dragging ability as suggested here, but the problem remains, because I am using element from outside the draggable list I believe.



In our production usecase, fixed element's index is variable, if that matters.







javascript vue.js draggable sortablejs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 15:20









EddoEddo

1126




1126












  • So the position of fixed element should not change? or are they just not draggable?

    – Sujil Maharjan
    Nov 13 '18 at 16:04












  • Position of fixed element should not change, there should always be the same number of draggable items before and after it. It will actually represent some kind of a threshold

    – Eddo
    Nov 13 '18 at 16:16











  • Why don't you make two lists? Otherwise the expectation doesn't really make sense. If there are 2 elements before fixed and 2 elements after fixed element --> then you move 1 element from before fixed to after, so, what will be the elements before fixed? an empty string?

    – Sujil Maharjan
    Nov 13 '18 at 16:34











  • Say you have A,B,Fixed,C,D and you move B inbetween C and D, then you should get A,C,Fixed,B,D Ideally I would like Fixed to be just a visual sign completely ignored by the draggable component logic

    – Eddo
    Nov 13 '18 at 16:44






  • 1





    I would listen to some onChange event and just manually move the elements above/below the fixed element. When using something like vue-draggable you have to remember that if it wasn't developed with the functionality you have in mind you're probably gonna have to create it yourself, i.e. moving them "manually" up and down. You can also fork vue-draggable or make a pull request in order to add the functionality so you can keep your code cleaner.

    – Simon Hyll
    Nov 14 '18 at 6:09

















  • So the position of fixed element should not change? or are they just not draggable?

    – Sujil Maharjan
    Nov 13 '18 at 16:04












  • Position of fixed element should not change, there should always be the same number of draggable items before and after it. It will actually represent some kind of a threshold

    – Eddo
    Nov 13 '18 at 16:16











  • Why don't you make two lists? Otherwise the expectation doesn't really make sense. If there are 2 elements before fixed and 2 elements after fixed element --> then you move 1 element from before fixed to after, so, what will be the elements before fixed? an empty string?

    – Sujil Maharjan
    Nov 13 '18 at 16:34











  • Say you have A,B,Fixed,C,D and you move B inbetween C and D, then you should get A,C,Fixed,B,D Ideally I would like Fixed to be just a visual sign completely ignored by the draggable component logic

    – Eddo
    Nov 13 '18 at 16:44






  • 1





    I would listen to some onChange event and just manually move the elements above/below the fixed element. When using something like vue-draggable you have to remember that if it wasn't developed with the functionality you have in mind you're probably gonna have to create it yourself, i.e. moving them "manually" up and down. You can also fork vue-draggable or make a pull request in order to add the functionality so you can keep your code cleaner.

    – Simon Hyll
    Nov 14 '18 at 6:09
















So the position of fixed element should not change? or are they just not draggable?

– Sujil Maharjan
Nov 13 '18 at 16:04






So the position of fixed element should not change? or are they just not draggable?

– Sujil Maharjan
Nov 13 '18 at 16:04














Position of fixed element should not change, there should always be the same number of draggable items before and after it. It will actually represent some kind of a threshold

– Eddo
Nov 13 '18 at 16:16





Position of fixed element should not change, there should always be the same number of draggable items before and after it. It will actually represent some kind of a threshold

– Eddo
Nov 13 '18 at 16:16













Why don't you make two lists? Otherwise the expectation doesn't really make sense. If there are 2 elements before fixed and 2 elements after fixed element --> then you move 1 element from before fixed to after, so, what will be the elements before fixed? an empty string?

– Sujil Maharjan
Nov 13 '18 at 16:34





Why don't you make two lists? Otherwise the expectation doesn't really make sense. If there are 2 elements before fixed and 2 elements after fixed element --> then you move 1 element from before fixed to after, so, what will be the elements before fixed? an empty string?

– Sujil Maharjan
Nov 13 '18 at 16:34













Say you have A,B,Fixed,C,D and you move B inbetween C and D, then you should get A,C,Fixed,B,D Ideally I would like Fixed to be just a visual sign completely ignored by the draggable component logic

– Eddo
Nov 13 '18 at 16:44





Say you have A,B,Fixed,C,D and you move B inbetween C and D, then you should get A,C,Fixed,B,D Ideally I would like Fixed to be just a visual sign completely ignored by the draggable component logic

– Eddo
Nov 13 '18 at 16:44




1




1





I would listen to some onChange event and just manually move the elements above/below the fixed element. When using something like vue-draggable you have to remember that if it wasn't developed with the functionality you have in mind you're probably gonna have to create it yourself, i.e. moving them "manually" up and down. You can also fork vue-draggable or make a pull request in order to add the functionality so you can keep your code cleaner.

– Simon Hyll
Nov 14 '18 at 6:09





I would listen to some onChange event and just manually move the elements above/below the fixed element. When using something like vue-draggable you have to remember that if it wasn't developed with the functionality you have in mind you're probably gonna have to create it yourself, i.e. moving them "manually" up and down. You can also fork vue-draggable or make a pull request in order to add the functionality so you can keep your code cleaner.

– Simon Hyll
Nov 14 '18 at 6:09












1 Answer
1






active

oldest

votes


















0














The problem is you need to include your "fixed elements" as data in the array you are passing to Vue.Draggable... You also cannot have the v-if because SortableJS will count those as an element, even though they are not visible, because VueJS leaves invisible elements with v-if's as comments... SortableJS will index these comments. So add an item to your array after John3, and get rid of the v-if.. instead, include a draggable property in your objects and only set the 'drag' class if that element has that draggable property set to true. The last issue is that Sortable will not index an element that is not draggable, but this will probably be fixed in a later update. I recommend you use filter option for now.



Example (not using filter): https://jsfiddle.net/3wrj07et/5/






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284154%2fhow-can-i-set-a-fixed-element-alongside-vue-draggable-list%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem is you need to include your "fixed elements" as data in the array you are passing to Vue.Draggable... You also cannot have the v-if because SortableJS will count those as an element, even though they are not visible, because VueJS leaves invisible elements with v-if's as comments... SortableJS will index these comments. So add an item to your array after John3, and get rid of the v-if.. instead, include a draggable property in your objects and only set the 'drag' class if that element has that draggable property set to true. The last issue is that Sortable will not index an element that is not draggable, but this will probably be fixed in a later update. I recommend you use filter option for now.



    Example (not using filter): https://jsfiddle.net/3wrj07et/5/






    share|improve this answer



























      0














      The problem is you need to include your "fixed elements" as data in the array you are passing to Vue.Draggable... You also cannot have the v-if because SortableJS will count those as an element, even though they are not visible, because VueJS leaves invisible elements with v-if's as comments... SortableJS will index these comments. So add an item to your array after John3, and get rid of the v-if.. instead, include a draggable property in your objects and only set the 'drag' class if that element has that draggable property set to true. The last issue is that Sortable will not index an element that is not draggable, but this will probably be fixed in a later update. I recommend you use filter option for now.



      Example (not using filter): https://jsfiddle.net/3wrj07et/5/






      share|improve this answer

























        0












        0








        0







        The problem is you need to include your "fixed elements" as data in the array you are passing to Vue.Draggable... You also cannot have the v-if because SortableJS will count those as an element, even though they are not visible, because VueJS leaves invisible elements with v-if's as comments... SortableJS will index these comments. So add an item to your array after John3, and get rid of the v-if.. instead, include a draggable property in your objects and only set the 'drag' class if that element has that draggable property set to true. The last issue is that Sortable will not index an element that is not draggable, but this will probably be fixed in a later update. I recommend you use filter option for now.



        Example (not using filter): https://jsfiddle.net/3wrj07et/5/






        share|improve this answer













        The problem is you need to include your "fixed elements" as data in the array you are passing to Vue.Draggable... You also cannot have the v-if because SortableJS will count those as an element, even though they are not visible, because VueJS leaves invisible elements with v-if's as comments... SortableJS will index these comments. So add an item to your array after John3, and get rid of the v-if.. instead, include a draggable property in your objects and only set the 'drag' class if that element has that draggable property set to true. The last issue is that Sortable will not index an element that is not draggable, but this will probably be fixed in a later update. I recommend you use filter option for now.



        Example (not using filter): https://jsfiddle.net/3wrj07et/5/







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 '18 at 18:36









        Owen MOwen M

        6601624




        6601624



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284154%2fhow-can-i-set-a-fixed-element-alongside-vue-draggable-list%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3