0

I want to do the row reorder functionality in jqgrid.

I have referred a sortable rows example given by trirand website,I can move rows up and down,

do we have any methods to get the row reordered and call ajax events for the moved row?

This is my grid:

jQuery(document).ready(function () {
    var pageWidth = $(window).width();
    var lastSel;
    $("#sortrows").setGridWidth(pageWidth);
    $('#sortrows').jqGrid('GridUnload');
    jQuery("#sortrows").jqGrid({            
        datatype: "local",
        mtype: "GET",
        hoverrows: false,
        jsonReader: { repeatitems: false, id: "Index" },
        ajaxGridOptions: { timeout: 30000 },
        colNames: PricelistHeaderColName,
        colModel: PricelistHeaderModel,
        id: 'Index',
        localReader: { id: 'Index' },
        prmNames: { id: "Index" },
        rowNum: 10,            
        rowList: [10, 20, 30],
        hidegrid: false,
        rownumbers: true,
        viewrecords: true,
        height: 'auto',
        width: pageWidth,
        scrollOffset: 0,
        gridview: true,
        autowidth:true,
        shrinkToFit: true,
        pager: '#psortrows',
        sortname: 'Description',
        autoencode: true,
        loadonce: true,
        ignoreCase: true,
        multiselect: false,
        viewrecords: true,
        sortorder: "asc",
        caption: "PriceList Headers",
        editurl: "../Header/Save",            

    });

    $('#sortrows').jqGrid('setLabel', 'Description', "Description", { 'text-align': 'left' });

    jQuery("#sortrows").jqGrid('navGrid', '#psortrows',
        {
            edit: false,
            add: false,
            del: false,

        });


    jQuery("#sortrows").jqGrid('inlineNav', '#psortrows',
        {
            add: true,
            addtext: "Add",
            addicon: "ui-icon-plus",
            edit: true,
            editicon: "ui-icon-pencil",
            edittext: "Edit",
            save: true,
            saveicon: "ui-icon-disk",
            savetext:"Save",
            cancel: true,
            cancelicon: "ui-icon-cancel",
            canceltext: "Cancel",
            search: true,
            searchtext: "Seaech",
            del: true,
            deltext: "Delete",
            delicon : "ui-icon-delete",

            // additional parameters below:
            editParams: inlineEditOptions,
            addParams: { addRowParams: inlineAddOptions }                

        });

    jQuery("#sortrows").jqGrid('sortableRows', { items: '.jqgrow:not(.unsortable)' });

    $('#sortrows').jqGrid('filterToolbar', { searchOnEnter: false, enableClear: false, defaultSearch: "cn", stringResult: true });

    //var myData = $('#sortrows').jqGrid('getDataIDs');        
    for (var i = 0; i < myData.length; i++) {            
        //jQuery("#sortrows").addRowData(myData[i].Code, myData[i]);
        $("#sortrows").jqGrid('addRowData', i + 1, myData[i]);

    }
    var recordCount = $("#sortrows").jqGrid('getGridParam', 'reccount');
    console.log(recordCount);

});

I need to call controller actions to save database changes after the row is reordered..I cant found the solution. Kindly help me on this............

BaluJagua
  • 25
  • 7
  • Look at [the answer](http://stackoverflow.com/a/3357770/315935). It seems that you need just use `update` option of `sortableRows`. – Oleg May 25 '15 at 12:45
  • You are welcome! Does it solves your problem? – Oleg May 25 '15 at 13:24
  • am working on it :@Oleg, will update you soon. – BaluJagua May 26 '15 at 04:49
  • :@Oleg Can we get all the rows after grid rows reordered. For example: am having 5 rows in grid. am moving 1st row down to the 2nd row. now the row index for the first record is changed in UI. Can I get that reordered grid rows? – BaluJagua May 26 '15 at 06:45
  • One can use `getLocalRow` to access the data of the row of the grid identified by rowid. By the way the code which you post is very dirty. You should for example never use `addRowData` in the loop to fill the grid. Instead of that `data: myData` parameter should be used. – Oleg May 26 '15 at 08:06

0 Answers0