Only one column of the table responsible for Drag and Drop - Touch Punch

Asked

Viewed 27 times

0

How to make only one table column responsible for performing the table row drag and drop using the jQuery UI Touch Punch event

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.2/jquery.ui.touch-punch.min.js"></script>


<script>
    $(document).ready(function () {
        $("#sortable").sortable({
            update: function (event, ui) {
                var itemIds = "";
                $("#sortable").find(".taskSingleInLine").each(function () {
                    var itemId = $(this).attr("data-taskid");
                    itemIds = itemIds + itemId + ",";
                });
                $.ajax({
                    url: '@Url.Action("UpdateItem", "Lotes")',
                    data: { itemIds: itemIds },
                    type: 'POST',
                    success: function (data) {
                        location.reload();
                    },
                    error: function (xhr, status, error) {

                    }
                });
            }
        });
        $("#sortable").disableSelection();

    });
</script>

HTML

<div class="table-responsive">
    <table class="table table-hover table-striped">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Lote.NumeroLote)
                </th>
            </tr>
        </thead>

        <tbody id="sortable" style="cursor:pointer">

            @for (var i = 0; i < Model.LoteList.Count(); i++)
            {
                <tr>
                    <td class="ui-state-default taskSingleInLine" id="task@(Model.LoteList.ElementAt(i).NumeroLote)" data-taskid="@(Model.Genero.ElementAt(i).GeneroId)-@(i+1)">
                        @Html.DisplayFor(Model => Model.LoteList.ElementAt(i).NumeroLote)
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>

inserir a descrição da imagem aqui

1 answer

0


Solution to my own question. I had to look and understand and so I am contributing to the community, and as amazing as it seems after learning this command, in the very forum stackoverflow but in English the friend jake-Wolpert also passed the solution, thus being credited to him the solution of the problem.

Link to the Documentation

$(document).ready(function() {

  $("#sortable").sortable({
    handle: ".drag-handler"
  });
  $("#sortable").disableSelection();

});

Demonstration

Browser other questions tagged

You are not signed in. Login or sign up in order to post.