HTML table onDrop event












-1















I have an HTML Table that I have both a mouse down event and a mouse up events and drag and drop rows works well. My only problem is that I can't figure out how to identify when the drop has completed. I need to loop the table rows and resort their row id's to save the sort order to a database. If I call it using the mouse up then the drop has not occurred. I've seen where a div can have a dropend or onDrop event but not a table. Is this possible?










share|improve this question

























  • Atleast try your logic, and post what you tried.

    – Jestin Sebastian
    Nov 20 '18 at 4:54
















-1















I have an HTML Table that I have both a mouse down event and a mouse up events and drag and drop rows works well. My only problem is that I can't figure out how to identify when the drop has completed. I need to loop the table rows and resort their row id's to save the sort order to a database. If I call it using the mouse up then the drop has not occurred. I've seen where a div can have a dropend or onDrop event but not a table. Is this possible?










share|improve this question

























  • Atleast try your logic, and post what you tried.

    – Jestin Sebastian
    Nov 20 '18 at 4:54














-1












-1








-1








I have an HTML Table that I have both a mouse down event and a mouse up events and drag and drop rows works well. My only problem is that I can't figure out how to identify when the drop has completed. I need to loop the table rows and resort their row id's to save the sort order to a database. If I call it using the mouse up then the drop has not occurred. I've seen where a div can have a dropend or onDrop event but not a table. Is this possible?










share|improve this question
















I have an HTML Table that I have both a mouse down event and a mouse up events and drag and drop rows works well. My only problem is that I can't figure out how to identify when the drop has completed. I need to loop the table rows and resort their row id's to save the sort order to a database. If I call it using the mouse up then the drop has not occurred. I've seen where a div can have a dropend or onDrop event but not a table. Is this possible?







javascript html5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 3:37









Dacre Denny

12.5k41031




12.5k41031










asked Nov 20 '18 at 3:36









user1314159user1314159

332210




332210













  • Atleast try your logic, and post what you tried.

    – Jestin Sebastian
    Nov 20 '18 at 4:54



















  • Atleast try your logic, and post what you tried.

    – Jestin Sebastian
    Nov 20 '18 at 4:54

















Atleast try your logic, and post what you tried.

– Jestin Sebastian
Nov 20 '18 at 4:54





Atleast try your logic, and post what you tried.

– Jestin Sebastian
Nov 20 '18 at 4:54












1 Answer
1






active

oldest

votes


















0














I was able to dig some more and came up with something that works



        $(function () {
$("#citationAreaTopTable tbody").sortable({
appendTo: "parent",
helper: getHelper, // "clone",
stop: function (event, ui) {

var attr = $(ui.item).attr('id');
var tableName = $(this).parent().attr("id");

$('#' + tableName + ' tr').each(function (event, ui) {
$(this).css('backgroundColor', 'white');
});


if (tableName == "citationAreaTopTable") {
var table = document.getElementById('citationAreaTopTable');
var pmidsText = '';
for (var i = 1; i < table.rows.length; i++) {
if (table.rows[i].cells.length) {
var id = (table.rows[i].id.substring(table.rows[i].id.indexOf("-") + 1));
pmidsText += id + ','
}
}
pmidsText = pmidsText.slice(0, -1);
$('#citationAreaTopList').html('<b>Selected PMIDS: </b>' + pmidsText);
}
},
update: function (event, ui) {

var tableName = $(this).parent().attr("id");
var id = '';
var index = 0;

if (tableName === '"citationAreaTopTable") ') {
//do something
}

$('#' + tableName + ' tr').each(function (e, u) {
$(this).css('backgroundColor', 'white');
if (u.id) {
if (u.id.slice(index).length > 0) {
id += u.id.slice(index) + ',';
}
}

});

Save_Sort(id);
}
}).disableSelection();


This allows me to loop the table and pull out the row id's






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%2f53385849%2fhtml-table-ondrop-event%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














    I was able to dig some more and came up with something that works



            $(function () {
    $("#citationAreaTopTable tbody").sortable({
    appendTo: "parent",
    helper: getHelper, // "clone",
    stop: function (event, ui) {

    var attr = $(ui.item).attr('id');
    var tableName = $(this).parent().attr("id");

    $('#' + tableName + ' tr').each(function (event, ui) {
    $(this).css('backgroundColor', 'white');
    });


    if (tableName == "citationAreaTopTable") {
    var table = document.getElementById('citationAreaTopTable');
    var pmidsText = '';
    for (var i = 1; i < table.rows.length; i++) {
    if (table.rows[i].cells.length) {
    var id = (table.rows[i].id.substring(table.rows[i].id.indexOf("-") + 1));
    pmidsText += id + ','
    }
    }
    pmidsText = pmidsText.slice(0, -1);
    $('#citationAreaTopList').html('<b>Selected PMIDS: </b>' + pmidsText);
    }
    },
    update: function (event, ui) {

    var tableName = $(this).parent().attr("id");
    var id = '';
    var index = 0;

    if (tableName === '"citationAreaTopTable") ') {
    //do something
    }

    $('#' + tableName + ' tr').each(function (e, u) {
    $(this).css('backgroundColor', 'white');
    if (u.id) {
    if (u.id.slice(index).length > 0) {
    id += u.id.slice(index) + ',';
    }
    }

    });

    Save_Sort(id);
    }
    }).disableSelection();


    This allows me to loop the table and pull out the row id's






    share|improve this answer




























      0














      I was able to dig some more and came up with something that works



              $(function () {
      $("#citationAreaTopTable tbody").sortable({
      appendTo: "parent",
      helper: getHelper, // "clone",
      stop: function (event, ui) {

      var attr = $(ui.item).attr('id');
      var tableName = $(this).parent().attr("id");

      $('#' + tableName + ' tr').each(function (event, ui) {
      $(this).css('backgroundColor', 'white');
      });


      if (tableName == "citationAreaTopTable") {
      var table = document.getElementById('citationAreaTopTable');
      var pmidsText = '';
      for (var i = 1; i < table.rows.length; i++) {
      if (table.rows[i].cells.length) {
      var id = (table.rows[i].id.substring(table.rows[i].id.indexOf("-") + 1));
      pmidsText += id + ','
      }
      }
      pmidsText = pmidsText.slice(0, -1);
      $('#citationAreaTopList').html('<b>Selected PMIDS: </b>' + pmidsText);
      }
      },
      update: function (event, ui) {

      var tableName = $(this).parent().attr("id");
      var id = '';
      var index = 0;

      if (tableName === '"citationAreaTopTable") ') {
      //do something
      }

      $('#' + tableName + ' tr').each(function (e, u) {
      $(this).css('backgroundColor', 'white');
      if (u.id) {
      if (u.id.slice(index).length > 0) {
      id += u.id.slice(index) + ',';
      }
      }

      });

      Save_Sort(id);
      }
      }).disableSelection();


      This allows me to loop the table and pull out the row id's






      share|improve this answer


























        0












        0








        0







        I was able to dig some more and came up with something that works



                $(function () {
        $("#citationAreaTopTable tbody").sortable({
        appendTo: "parent",
        helper: getHelper, // "clone",
        stop: function (event, ui) {

        var attr = $(ui.item).attr('id');
        var tableName = $(this).parent().attr("id");

        $('#' + tableName + ' tr').each(function (event, ui) {
        $(this).css('backgroundColor', 'white');
        });


        if (tableName == "citationAreaTopTable") {
        var table = document.getElementById('citationAreaTopTable');
        var pmidsText = '';
        for (var i = 1; i < table.rows.length; i++) {
        if (table.rows[i].cells.length) {
        var id = (table.rows[i].id.substring(table.rows[i].id.indexOf("-") + 1));
        pmidsText += id + ','
        }
        }
        pmidsText = pmidsText.slice(0, -1);
        $('#citationAreaTopList').html('<b>Selected PMIDS: </b>' + pmidsText);
        }
        },
        update: function (event, ui) {

        var tableName = $(this).parent().attr("id");
        var id = '';
        var index = 0;

        if (tableName === '"citationAreaTopTable") ') {
        //do something
        }

        $('#' + tableName + ' tr').each(function (e, u) {
        $(this).css('backgroundColor', 'white');
        if (u.id) {
        if (u.id.slice(index).length > 0) {
        id += u.id.slice(index) + ',';
        }
        }

        });

        Save_Sort(id);
        }
        }).disableSelection();


        This allows me to loop the table and pull out the row id's






        share|improve this answer













        I was able to dig some more and came up with something that works



                $(function () {
        $("#citationAreaTopTable tbody").sortable({
        appendTo: "parent",
        helper: getHelper, // "clone",
        stop: function (event, ui) {

        var attr = $(ui.item).attr('id');
        var tableName = $(this).parent().attr("id");

        $('#' + tableName + ' tr').each(function (event, ui) {
        $(this).css('backgroundColor', 'white');
        });


        if (tableName == "citationAreaTopTable") {
        var table = document.getElementById('citationAreaTopTable');
        var pmidsText = '';
        for (var i = 1; i < table.rows.length; i++) {
        if (table.rows[i].cells.length) {
        var id = (table.rows[i].id.substring(table.rows[i].id.indexOf("-") + 1));
        pmidsText += id + ','
        }
        }
        pmidsText = pmidsText.slice(0, -1);
        $('#citationAreaTopList').html('<b>Selected PMIDS: </b>' + pmidsText);
        }
        },
        update: function (event, ui) {

        var tableName = $(this).parent().attr("id");
        var id = '';
        var index = 0;

        if (tableName === '"citationAreaTopTable") ') {
        //do something
        }

        $('#' + tableName + ' tr').each(function (e, u) {
        $(this).css('backgroundColor', 'white');
        if (u.id) {
        if (u.id.slice(index).length > 0) {
        id += u.id.slice(index) + ',';
        }
        }

        });

        Save_Sort(id);
        }
        }).disableSelection();


        This allows me to loop the table and pull out the row id's







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 12:51









        user1314159user1314159

        332210




        332210
































            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%2f53385849%2fhtml-table-ondrop-event%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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini