0

I am using draggable jqgrid.But the issue is the rows are draggable only in the first page.After I change the pagination, the draggable for rows is not working.Can you please help me. Below is my code for making jqgrid rows draggable.

function GetAllCompanyProducts(productData) {
/// <summary>method to load the Proposal grid</summary>
//Load the grid
var tabelWidth = $("#tblCompanyProducts").width();

jQuery("#tblCompanyProducts").jqGrid({
    datatype: 'local',
    data: productData,
    jsonReader: { repeatitems: false },
    loadui: "block",
    autowidth: true,
    mtype: 'get',
    rowNum: 30,
    rowList: [30, 100, 200],
    viewrecords: true,
    colNames: ['ProductId', 'ProductName', 'Price'],
    colModel: [
        { name: 'ProductId', index: 'ProductId', width: '30%' },
        { name: 'ProductName', index: 'ProductName', width: '30%' },
        { name: 'Price', index: 'Price', width: '30%' }
    ],
    sortname: 'ProductId',
    sortorder: 'asc',
    caption: "Product List",
    width: tabelWidth - 10,
    pager: '#divPager',
    height: "100%",
    hoverrows: true,
    onPaging: function () {
        $("#tblCompanyProducts").trigger('reloadGrid');
    },

});    


$("#tblCompanyProducts").jqGrid('setGridParam', { gridComplete: MakeGridRowsDraggable($("#" + this.id)) });

}

And below is the method

function MakeGridRowsDraggable(grid) {
/// <summary></summary>
/// <param name="grid" type=""></param>

//$("#tblCompanyProducts").val(new Date().getTime());
var searchResultsRows = $("#tblCompanyProducts .ui-row-ltr");

searchResultsRows.draggable({ appendTo: "body" }); searchResultsRows.draggable({
    create: function (event, ui) { }
});

searchResultsRows.css("cursor", "move").draggable("option", "helper", "clone").draggable({
    revert: "true",
    appendTo: 'body',
    cursor: "move",
    snap: "true",
    cursorAt: {
        top: 10,
        left: -5
    },
    helper: function (event) {
        //get a hold of the row id
        var rowId = $(this).attr('id');

        var rowData = $("#tblCompanyProducts").getRowData(rowId);
        var  id = parseInt(rowData['ProductId']) + "-" + rowData['ProductName'] + "-" + rowData['Price'];
        //set the data on this to the value to grab when you drop into input box
        $(this).data('colValue', id);
        var dialog = ($('#DragableWidget').length > 0) ? $('#DragableWidget') :
                     $('<div id="DragableWidget" class="draggedValue ui-widget-header ui-corner-all"></div>').appendTo('body');
        dialog.html(id);
        return dialog;
    }
    , start: function (event, ui) {
    }
    , stop: function (event, ui) {
        $(this).parent().fadeTo(0, 1);
    }
});

}

sandeep.mishra
  • 825
  • 4
  • 19
  • 40

1 Answers1

2

I fixed the issue by calling the method on loadcomplete with timeout. below is the code

  loadComplete: function () {
            setTimeout(function () {
                MakeGridRowsDraggable($("#" + this.id));
            }, 2000);

It worked well for me.:)

sandeep.mishra
  • 825
  • 4
  • 19
  • 40