我有一个使用 IgniteUI 16.2 版的 Infragistics 的 igGrid。
我正在尝试使用 jQuery UI 1.11.4 版(结合 jQuery 1.11.3 版)中的“可拖动”库使行可拖动。
我的“可放置”目标是 igGrid 之外的一个 div。
只要我留在网格内,我就可以很好地拖放行。但是,一旦我尝试将行拖到网格之外,网格就会开始滚动。
这是我的 jQuery,它将行转换为“可拖动”元素:
$("#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 库渲染后的可滚动部分:
<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 可以修改“开始”事件上的网格以防止其滚动。我也尝试过摆弄该overflow-y
属性,因为对于我不懂 CSS 的大脑来说,这似乎是显而易见的答案,但没有任何帮助。
编辑: 这是按要求提供的 JS Fiddle