向表行添加可拖动(使用Kendo Grid)

时间:2013-01-10 22:01:19

标签: jquery jquery-selectors draggable kendo-ui

我正在尝试在表格的行上添加一个可拖动的事件,但我没有得到我应该得到的东西。这是一个创建表结构的Kendo Grid。最后,如果可能的话,我想放弃一些不是剑道的行。

HTML

<div id="Assets" style="width: 200px; float: left;" data-role="grid" class="k-grid k-widget" tabindex="0">
    <ul>
        <div class="k-widget k-grid" id="Assets">
            <div class="k-grid-header">
                <div class="k-grid-header-wrap">
                    <table cellspacing="0">
                        <colgroup>
                        <col style="width: 240px">
                    </colgroup>
                    <tbody></tbody>
                </table>
            </div>
        </div>
        <div class="k-grid-content" style="height: 200px">
            <div class="k-grid-header" style="padding-right: 17px;">
                <div class="k-grid-header-wrap">
                    <table cellspacing="0">
                        <colgroup><col style="width: 240px"></colgroup>
                        <thead>
                            <tr data-role="draggable">
                                <th class="k-header" data-field="Id" data-title="Id" scope="col" style="display: none"><span class="k-link">Id</span></th>
                                <th class="k-header" data-field="Name" data-title="Name" scope="col"><span class="k-link">Name</span></th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
        <table cellspacing="0" class="k-focusable">
            <colgroup><col style="width: 240px"/></colgroup>
            <tbody>
                <tr data-uid="cc7fc98a-dc66-4a46-8d3a-b73d608cf32b">
                    <td style="display: none">1</td>
                    <td>A Commons</td>
                </tr>
                <tr class="k-alt" data-uid="daf17bf4-52d3-43a4-acc0-034c7c53e5af">
                    <td style="display: none">2</td>
                    <td>A Chase</td>
                </tr>
                <tr data-uid="6dbe2dec-e9ce-4640-8f61-f1ee4469a581">
                    <td style="display: none">4</td>
                    <td>Beacon</td>
                </tr>
                <tr class="k-alt" data-uid="569798d6-433c-4dea-b56b-5833bab22058">
                    <td style="display: none">5</td>
                    <td>Seminole</td>
                </tr>
                <tr data-uid="4639277c-97eb-43d0-9aa1-6402671474b5">
                    <td style="display: none">6</td>
                    <td>Commons</td>
                </tr>
                <tr class="k-alt" data-uid="9ad1bf14-91bf-474f-9115-246c55c38eab">
                    <td style="display: none">3</td>
                    <td>Willows</td>
                </tr>
            </tbody>
        </table>
    </ul>
</div>

JS

这是我的代码试图选择我需要的tr:

$(".k-focusable > tbody > tr").kendoDraggable({
    hint: function(e) {
        item = $('<div class="k-grid k-widget" style="background-color: lightblue; color: black;"><table><tbody><tr>' + e.html() + '</tr></tbody></table></div>');
        return item;
    },
});

我更愿意以纯jQuery的方式做到这一点:

$("<selector>").draggable({
    cursor: 'move',
    distance: 40,
    helper: 'clone',
    opacity: 0.8,
    revert: 'invalid',
    revertDuration: 100,
    snap: 'div.node.expanded',
    snapMode: 'inner',
    stack: 'div.node',
});

1 个答案:

答案 0 :(得分:3)

不知道丢弃时你想做什么,但是这应该可以将一行从Kendo Grid移动到可放置的区域但是它实际上并没有从{{1}中删除元素所以你应该(或不是?)。

我删除的内容是grid要移动的元素,并将此clone插入目标区域。

HTML code:

clone

JavaScript Grid初始化:

<div id="grid"></div>
<table id="target" class="k-widget k-grid">
    <thead>
        <tr>
            <th class="k-header" colspan="2">Drop inside red area</th>
        </tr>
    </thead>
</table>

最后是拖放:

var dataSource = new kendo.data.DataSource({
    data    : [
        {"ID": 1, "Nom": "John"},
        {"ID": 2, "Nom": "Jane"},
        {"ID": 3, "Nom": "Sam"},
        {"ID": 4, "Nom": "Charles"},
        {"ID": 5, "Nom": "Paul"},
        {"ID": 6, "Nom": "Josh"},
        {"ID": 7, "Nom": "Daniel"}
    ],
    pageSize: 8
});

var grid = $("#grid").kendoGrid({
    dataSource: dataSource,
    columns   : [
        {field: "ID" },
        {field: "Nom"}
    ]
}).data("kendoGrid");

看到它正在运行here