How to initialize a jqGrid with the proper events for row re-ordering (Sortable)

前端 未结 2 1938
梦毁少年i
梦毁少年i 2020-12-10 00:26

I\'d like to be able to subscribe to the events that are raised during a Sortable drag and drop operation (New in 3.6 Sortable Rows) as I need to persist this information ba

2条回答
  •  鱼传尺愫
    2020-12-10 00:59

    Current implementation that works is

    $('#favoriteGrid').bind("sortstart", function (event, ui) {
        // I had no need for this action
    });
    
    $('#favoriteGrid').bind("sortstop", function (event, ui) {
    
        var lista = jQuery("#favoriteGrid").getDataIDs();
        var items = [];
    
        for (i = 0; i < lista.length; i++) {
            var rowData = jQuery("#favoriteGrid").getRowData(lista[i]);
            items.push({ productId: rowData.ProductId, rowNum: i });
        }
    
        var fromFolder = $("#favorite-products > a.selected").attr("data-folderId");
        var payload = { FolderId: fromFolder, Items: items };
    
        $.blockUI({ message: '

    Saving your sort order...

    ' }); $.ajax({ type: "POST", url: "/xxx/yyy/zzz/", data: JSON.stringify(payload), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { $("#favoriteStatusMessages").html(data) $.unblockUI(); }, failure: function (errMsg) { $("#favoriteStatusMessages").html(errMsg).addClass("ui-state-error"); $.unblockUI(); } }); });

提交回复
热议问题