Question

i want implement Delete for jqGrid, i have (example) 2 table Request and Item

Request Fields are RequestId,WayBillNo,Customer
Item Fields are RequestId,ItemNO,Quantity
Request table RequestId is pk and in item table pk are RequestId,ItemNO i write this code for item table

var requestIdItem=0, itemIdItem=0;
var gridItem = $('#listItem');
gridItem.jqGrid({
    url: 'jQGridHandler.ashx',
    postData: { ActionPage: 'ClearanceItems', Action: 'Fill', requestId: rowid },
    ajaxGridOptions: { cache: false },
    datatype: 'json',
    height: 200,
    colNames: ['RequestId','ItemNo',Quantity],
    colModel: [
        { name: 'REQUEST_ID', width: 100, sortable: true,hidden:true },
        { name: 'ITEM_NO', width: 200, sortable: true }
        { name: 'Quntity', width: 100, sortable: true  }
    ],
    gridview: true,
    rowNum: 20,
    rowList: [20, 40, 60],
    pager: '#pagerItem',
    viewrecords: true,
    sortorder: 'ASC',
    rownumbers: true,
    //onSelectRow: function (id, state) {
    //    requestIdItem = gridItem.jqGrid('getCell', id, 'REQUEST_ID_ID');
    //    alert(requestIdItem);
    //    itemIdItem = gridItem.jqGrid('getCell', id, 'ITEM_NO');
    //    alert(itemIdItem);
    //}
    //,
    beforeSelectRow: function (itemid, ex) {
        requestIdItem = gridItem.jqGrid('getCell', itemid, 'REQUEST_ID_ID');
        itemIdItem = gridItem.jqGrid('getCell', itemid, 'ITEM_NO');

        return true;
    }

});
gridItem.jqGrid('navGrid', '#pagerItem', { add: false, edit: false, del: true }, {}, {}, {
    //alert(requestIdItem);
    url: "JQGridHandler.ashx?ActionPage=ClearanceItems&Action=Delete&REQUEST_ID=" +
         requestIdItem + "&ITEM_NO=" + itemIdItem
}, { multipleSearch: true, overlay: false, width: 460 });

i write this code for item table , now i want write code for delete item in Item table i write this code for send parameters value

url: "JQGridHandler.ashx?ActionPage=ClearanceItems&Action=Delete&REQUEST_ID=" +
     requestIdItem + "&ITEM_NO=" + itemIdItem

but always send 0 value to server, please help me. thanks all

EDIT01: i change Delete Option For this: I see in this page http://stackoverflow.com/questions/2833254/jqgrid-delete-row-how-to-send-additional-post-data user @Oleg write this code

gridItem.jqGrid('navGrid', '#pagerItem', { add: false, edit: false, del: true }, {}, {}, {
    serializeDelData: function (postdata) {
        alert(postdata.id);
        return ""; // the body MUST be empty in DELETE HTTP requests
    },
    onclickSubmit: function (rp_ge, postdata) {
        //  alert(postdata.id);
        var rowdata = $("#listItem").getRowData(postdata.id);
        alert(rowdata.REQUEST_ID_ID);
        rp_ge.url = 'JQGridHandler.ashx?ActionPage=ClearanceItems&Action=Delete&' +
                    $.param({ rr: rowdata.REQUEST_ID_ID });

        // 'subgrid.process.php/' + encodeURIComponent(postdata.id) +
        //    '?' + jQuery.param({ user_id: rowdata.user_id });
    }
    //alert(requestIdItem);
    // url: "JQGridHandler.ashx?ActionPage=ClearanceItems&Action=Delete&REQUEST_ID=" +
    //      requestIdItem + "&ITEM_NO=" + itemIdItem
}, { multipleSearch: true, overlay: false, width: 460 })

when send Data to server send undefined

Was it helpful?

Solution

First of all it seems to me that you have typing error in your code. You should replace REQUEST_ID_ID to REQUEST_ID everywhere in your code.

If you need to send some additional information to the server you can use

onclickSubmit: function (rp_ge, postdata) {
    var requestId = $(this).jqGrid("getCell", postdata.id, "REQUEST_ID");
    // alert("REQUEST_ID=" + requestId);
    return { rr: requestId });
}

In the case rr will be posted as additional parameter of the Delete request together with id parameter.

If you need really send the information as the part of URL instead of the part of body of the POST request you can do the following

onclickSubmit: function (rp_ge, postdata) {
    var requestId = $(this).jqGrid("getCell", postdata.id, "REQUEST_ID");
    // alert("REQUEST_ID=" + requestId);
    rp_ge.url = "JQGridHandler.ashx?" +
        $.param({
            ActionPage: "ClearanceItems",
            Action: "Delete",
            rr: requestId
        });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top