0
votes

I'm fairly new to kendo UI but some how I managed to render a kendo grid with drag and drop feature Where users can drag and place rows.In my case I have three columns id,name,sequence

So I need to keep sequence column data unchanged while id and name data changed when a drag and drop of a row.

Ex id=1 Name=David Sequnce=0
   id=2 Name=Mark  Sequnce=1

Now I'm going to drag row 1 to 2 while data of the sequence column remain unchanged new data like this,

Ex id=2 Name=Mark   Sequnce=0
   id=1 Name=David  Sequnce=1

In my case every row is getting changed. I need to implement this solution.

Can somebody help me out on this.

Cheers,

Chinthaka

1
Thanks martin For your kind response Cheers ;-)Chinthaka Devinda

1 Answers

1
votes

Try this,

Script

<script type="text/javascript">

    $(document).ready(function () {
    var data = [
{ id: 1, text: "David ", Sequnce: 0 },
{ id: 2, text: "Mark  ", Sequnce: 1 }
]

    var dataSource = new kendo.data.DataSource({
        data: data,
        schema: {
            model: {
                id: "id",
                fields: {
                    id: { type: "number" },
                    text: { type: "string" },
                    Sequnce: { type: "number" }
                }
            }
        }
    });

    var grid = $("#grid").kendoGrid({
        dataSource: dataSource,
        scrollable: false,
        columns: ["id", "text", "Sequnce"]
    }).data("kendoGrid");

    grid.table.kendoDraggable({
        filter: "tbody > tr",
        group: "gridGroup",
        hint: function (e) {
            return $('<div class="k-grid k-widget"><table><tbody><tr>' + e.html() + '</tr></tbody></table></div>');
        }
    });

    grid.table/*.find("tbody > tr")*/.kendoDropTarget({
        group: "gridGroup",
        drop: function (e) {
            var target = dataSource.get($(e.draggable.currentTarget).data("id"));
        dest = $(e.target);

            if (dest.is("th")) {
                return;
            }
            dest = dataSource.get(dest.parent().data("id"));

            //not on same item
            if (target.get("id") !== dest.get("id")) {
                //reorder the items
                var tmp = target.get("Sequnce");
                target.set("Sequnce", dest.get("Sequnce"));
                dest.set("Sequnce", tmp);

                dataSource.sort({ field: "Sequnce", dir: "asc" });
            }
        }
    });     

    });

</script>

View

<div id="grid">
</div>

Demo: http://jsfiddle.net/nmB69/710/