首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >igGrid + jQuery UI拖放

igGrid + jQuery UI拖放
EN

Stack Overflow用户
提问于 2017-10-02 18:48:31
回答 1查看 605关注 0票数 3

我有一个使用igGrid版本16.2的IgniteUI。

我试图使用jQuery UI版本1.11.4中的" draggable“库(与jQuery版本1.11.3相结合)使行可拖动。

我的“可下垂”目标是igGrid之外的div。

只要我保持在网格中,我就可以拖放行。但是,一旦我试图将行拖出网格,网格就开始滚动。

下面是我的jQuery,它将行转换为“可拖动”元素:

代码语言:javascript
复制
$("#grid > tbody > tr").draggable({
    helper: "clone",
    revert: "invalid",
    cursorAt: { bottom: 0, left: 0 },
    start: function (evt, ui) {

        // get the id of the row being dragged
        var row_id = ui.helper.prevObject.data("id");

        // get a reference to the <tr> being dragged
        var original_row_element = $("#grid > tbody > tr[data-id='" + row_id + "']");

        // get the collection of all <tr>'s that come after the selected row
        var all_rows_after_the_original = original_row_element.nextAll("tr");

        // move all those rows to a temporary holding <div> outside of the grid
        $("#temp_row_holder").append(all_rows_after_the_original);

    },
    stop: function (evt, ui) {

        // get all those rows that we moved out of the grid earlier
        var all_rows_after_the_original = $("#temp_row_holder").children("tr");

        // move the <tr>'s back into the grid
        $("#grid > tbody").append(all_rows_after_the_original);

    }
});

下面是我的网格中可滚动的部分,一旦它被Infragistics库呈现出来了:

代码语言:javascript
复制
<div id="grid_scroll" class="ui-iggrid-scrolldiv ui-widget-content igscroll-touchscrollable" data-scroll="true" data-onedirection="true" data-xscroller="#grid_hscroller" style="overflow-x: hidden; overflow-y: auto; height: 311px;">
    <table id="grid" role="grid" aria-describedby="grid_scroll" cellpadding="0" cellspacing="0" border="0" class="ui-iggrid-table ui-widget-content" style="table-layout: fixed;">
        <colgroup></colgroup>
        <tbody role="rowgroup" class="ui-widget-content ui-iggrid-tablebody ui-ig-record ui-iggrid-record">
            <tr data-id="c3bf5936-8786-e711-8135-caf5c8230062" role="row" tabindex="0" class="open-hand-pointer ui-draggable ui-draggable-handle"></tr>
            <tr class="ui-ig-altrecord ui-iggrid-altrecord open-hand-pointer ui-draggable ui-draggable-handle" data-id="a2a54d20-5a83-e711-8135-caf5c8230062" role="row" tabindex="0"></tr>
            <tr data-id="ca784490-cb82-e711-8135-caf5c8230062" role="row" tabindex="0" class="open-hand-pointer ui-draggable ui-draggable-handle"></tr>
            <tr class="ui-ig-altrecord ui-iggrid-altrecord open-hand-pointer ui-draggable ui-draggable-handle" data-id="4d95ba39-cd81-e711-8135-caf5c8230062" role="row" tabindex="0"></tr>
            <tr data-id="7b02f501-cb81-e711-8135-caf5c8230062" role="row" tabindex="0" class="open-hand-pointer ui-draggable ui-draggable-handle"></tr>
        </tbody>
    </table>
</div>

正如您所看到的,我目前的解决方案是从网格中删除所有同级<tr>,这样当我拖动行时它就不会滚动。这个解决方案工作得很好,但是从最终用户的角度来看,它显然是不可接受的,因为它们的所有行在它们开始拖动时突然消失。

似乎有一些CSS或javascript可以修改"start“事件上的网格,以防止其滚动。我也尝试过摆弄overflow-y属性,因为对我的CSS无知的大脑来说,这似乎是显而易见的答案,但没有任何帮助。

编辑:根据请求, 这里是一个JS

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-05 03:15:09

您可以使用滚动选项。默认情况下,它是true,并在拖动时导致自动滚动。你需要scroll: false来防止像这样的自动卷轴:

代码语言:javascript
复制
$("#GRIDRFDList > tbody > tr").draggable({
        helper: "clone",
        revert: "invalid",
        cursorAt: { bottom: 0, left: 0 },
        scroll: false // Add this line
    });

在线输出(小提琴)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46531802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档