使用UI Sortable,当我单击按钮时,是否可以根据给定的值将项目移动到新位置?

索比

当我单击一些将值传递给任何可能的UI事件的链接或按钮时,是否有一种方法可以强制UI Sortable更改列表中项目的位置?

这里的Sortable函数:

$("#sortable").sortable({
    start: function(event, ui) {
       // ... 
    },
    update: function(event, ui) {
       // ... 
    },
    stop: function(event, ui) {
       // ... 
    }
});

这是一个偶数按钮,用于更新特定行中文本输入的值...实际上触发了一个Ajax,但是我在这里简化了它:

$("#sortable tr").on("click", ".row-button", function () {
    var sort_id = $this.closest('tr').find('.text-sort-id').val();
    ...
    ...
});

更新:

这是我到目前为止所做jsFiddle结果。我需要能够将第二行的输入更改为“ 5”,然后单击“更改”以将其视觉上移至表格的底部,依此类推,例如,当第四行的输入更改为“ 1”时。

我希望能够在单击“更改”按钮时更改项目值,而无需重置所有其他项目,而又要从另一侧进行更改,能够拖动任何行并将其输入值更改为小于此后的值,然后小于其之前的输入值,并且此值即使我们需要设置一个相等的值,所有这些都不会更改其他值。

亚斯

请查看代码中的注释,以了解我在做什么。我已.sort-btn click使用以下代码更新了该事件:

$(".grid-sort-table tbody tr").on("click", ".sort-btn", function() {
    var allItems = $('.ui-sortable').children();

    //Select all of the input values
    var orderedInputValues = $.map(allItems, function(item) {
            return $(item).find('input').val();
    });

    //Order the input values (smallest to largest, by default)
    orderedInputValues = orderedInputValues.sort(); 

    //Store the "tr" in a variable so it can be manipulated.
    var selectedItem = $(this).closest('tr');
    var selectedItemVal = $(selectedItem).find('input').val();

    var indexToInsertAt = 0;
    for (var i = 0; i < orderedInputValues.length; i++) {
        if (orderedInputValues[i] == selectedItemVal) {
        indexToInsertAt = i;
        break;
      }
    }

    //Find the item at the index the selected item will be inserted at (before or after)
    var itemAtIndex = allItems[indexToInsertAt];

    //If the selected item's value is greater than the item at the required index, insert it after the item.
    if ($(selectedItem).find('input').val() > $(itemAtIndex).find('input').val()) {
        selectedItem.insertAfter(itemAtIndex);
    }
    else { //Otherwise, insert it before the item at the required index.
        selectedItem.insertBefore(itemAtIndex);
    }
    //Additional code below
    ...
});

更新的小提琴

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

当我尝试使用jQuery UI隐藏div时,为什么它会在滑动之前向下移动?

当我使用新的android项目appcompt时显示错误

将UI RectTransform移动到世界位置

回应:使用Material UI图标作为按钮?

如何使用jQuery UI Sortable正确相交?

使用RegEx是否可以将子字符串移动到特定位置?

使用UI按钮移动游戏对象

使用reactjs和Material UI单击按钮时更改内容

使用Blazor重写JavaScript单击并显示UI

jQuery UI.Sortable在将li移动到溢出底部时跳转

使用OperationQueue时更新UI

当我单击按钮时,输入完全不显示。如果我删除html表单,则可以使用,但我希望它可以在表单中使用

使用jQuery UI Sortable显示隐藏

当我使用javascript更新文本时,光标会移动到文本开头

使用NSURLSession时,UI被阻止

OpenGL- C ++,使用鼠标单击将形状移动到单击位置

jQuery UI Sortable-单击按钮时保存顺序

我可以在C ++ OpenGL项目中使用什么UI?

使用AsyncTaskLoader更新位置数据UI?

当我单击编辑按钮时,使用 mvc 不显示下拉值?

是否可以在移动时单击按钮,并在 iOS 中使用动画?

通过单击 UI 按钮而不是多次单击,将游戏对象移动或缓慢移动到其他游戏对象的位置?

通过 JavaScript 使用 Canvas,如何使圆圈移动到我单击的位置?

当我使用js单击按钮时如何隐藏表格?

使用 Kotlin 在按钮单击时移动到新活动,不传递任何信息,代码尽可能简单

当我使用列表视图时,UI 显示为白色

通过代码使用约束移动 UI 元素

当使用 Reindex API 将数据从一个索引移动到另一个索引时,我是否可以使用脚本来检测是否存在匹配的文档并进行部分更新?

如果我使用 ui:composite 和 ui:insert, ui:include,我是否必须在模板中传递 ui:param?