Why loadComplete fires before gridComplete? - jqgrid

I am trying to manipulate the data fetched from the server in loadComplete event:
loadComplete:function(data){
alert("load completed");
$.each (data,function(index,item){
item["customerSite"]=item.header.customerName + ' / '+item.header.siteDescription;
});
}
The newly added field is meant to be used as a column to be grouped by
However I keep getting this column as undefined as grouping header. I tried adding another field to the JSON object as a regular column, the column ends up to be empty. As I was debugging I noticed the grid is constructed before my breakpoint in the loadComplete stops.
My understanding of the loadComplete event is that it will fired as soon as the ajax call has success return. After I introduced gridComplete event to my code, I noticed gridComplete is invoked before loadComplete is invoked.
gridComplete: function(){
alert("grid completed");
}
What I am doing wrong? I am using
jsonReader: {
repeatitems: false,
id: "id",
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
to process returned JSON string, but cannot imagine that might be the problem. Please help!
Base on Oleg's comment, I will use custom formatter. However the result of the fomratter does not work for the group header, which this column is for. If I set groupColumnShow : [true], the column's data is all correct, but still leaves the group header to be 'undefined'
Following grid's definition:
buildGrid:function(){
var myGrid = jQuery("#serverList");
myGrid.jqGrid({
datatype: "json",
url: "http://localhost:8080/cm.server/api/v1/agent/config.json?",
jsonReader: {
repeatitems: false,
id: "id",
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
},
colNames:['Customer/Site','Customer','Site','Server ID', 'Server Name', ,'id'],
colModel :[
{name:'customerSite',editable:false, formatter:that.buildCustmerSite},
{name:'header.customerName',hidden:true,editable:true,editrules:{edithidden:true},editoptions:{readonly:true,size:25},formoptions:{ rowpos:1,elmprefix:" "}},
{name:'header.siteDescription', hidden:true, editable:true,editrules:{edithidden:true},editoptions:{readonly:true,size:25},formoptions:{ rowpos:2,elmprefix:" "}},
{name:'header.serverID', index:'header.serverID', width:200, align:'right',editable:true,editoptions:{readonly:true,size:25},formoptions:{ rowpos:3,elmprefix:" "}},
{name:'header.serverName', index:'header.serverName', width:150, align:'right',editable:true,editoptions:{readonly:true,size:25},formoptions:{ rowpos:4,elmprefix:" "}},
{name:'id', hidden:true},
],
height: '500',
width: '100%',
rowNum:20,
autowidth: true,
pager: '#pager',
sortname: 'serverID',
sortorder: "desc",
viewrecords: true,
caption: 'Server Configurations',
editurl:"/cm.server/api/v1/agent/config-grid",
autoencode:true,
ignoreCase:true,
grouping:true,
groupingView:{
groupField:['customerSite'],
groupColumnShow : [false]
}
});
jQuery("#serverList").jqGrid('navGrid','#pager',
{edit:true,add:false,del:false,search:true},
{height:450,reloadAfterSubmit:true, recreateForm:true,jqModal:true, closeOnEscape:true, closeAfterEdit:true, bottominfo:"Fields marked with (*) are required"}, // edit options
{} // search options
);
jQuery("#serverList").jqGrid('filterToolbar');
return true;
}
and following is the custom formatter:
buildCustmerSite:function(cellvalue,options,rowObject){
var customerSite =rowObject.header['customerName'] + '/'+ rowObject.header["siteDescription"];
return customerSite;
}

There are small differences between loadComplate and gridComplete, but both will be called after the grid contain is prepared. So you can't just modify the data of the loadComplate to change the grid contain.
You don't posted the definition of your grid, so it is difficult to answer on your question exactly. What you probably want can be solved with respect of the custom formatter which you can define for the customerSite column. Inside of formatter function you have access to rowObject where you find source information to construct the customerName + ' / ' + siteDescription.

Related

Which event gets fired when delete row occurs?

Grid contains after save row event "jqGridInlineAfterSaveRow" which works if you edit or add row.
//--Bind events...
console.log('Bind events...');
$("#jqGrid").bind("jqGridInlineAfterSaveRow",function (e, rowid, jqXhrOrBool, postData, options) {
console.log('EVENT:jqGridInlineAfterSaveRow');
var item = $(this).jqGrid('getLocalRow', rowid);
console.log(item);
console.log('BEFORE:');
saveObject(item);
console.log('AFTER:');
});
What is name of the event for delete row? i need to bind my JS function for delete row.
UPDATE 1
I am trying following option now, but no luck...
}).jqGrid("navGrid", "#jqGridPager", {edit: false, add: false, del: false, refresh: false, view: false,search: false,
delfunc: function (rowids) {
console.log(rowids);
}
})
UPDATE 2
I think issue is with delete buttons at row level not at footer
see the screenshot [enter image description here][1]
data:rdata,
colModel: [
{
label: "",
name: "",
width: 70,
formatter: "actions",
formatoptions: {
keys: true,
editOptions: {},
addOptions: {},
delOptions: { delfunc : function (id){
console.log(">>>>>>>>>>>>>>>>1");
}}
}
},
UPDATE 3
Based on Oleg's input, i have changed the code as following:
$("#jqGrid").bind("jqGridAfterDelRow",function (e, rowid, jqXhrOrBool, postData, options) {
console.log('EVENT:jqGridAfterDelRow');
console.log(rowid);
var item = $(this).jqGrid('delRowData ', rowid);
console.log(item);
console.log('BEFORE:');
console.log('AFTER:');
});
But now, i am not getting deleted row object??? Actually, i need to get the some of the fields from deleted row e.g. ID. and above binding function will in turn call server side ajax function.
UPDATE 4
Thanks to Oleg for supporting beyond... Here is the code i have mashup from one of the answers from him.
colModel: [
{
label: "",
name: "",
width: 70,
formatter: "actions",
formatoptions: {
keys: true,
editbutton : true,
delbutton : true,
editOptions: {},
addOptions: {},
delOptions: {
onclickSubmit: function(options, rowid) {
console.log("delOptions::onclickSubmit");
var grid_id = $.jgrid.jqID(grid[0].id);
var grid_p = grid[0].p;
var newPage = grid[0].p.page;
var rowdata = grid.getLocalRow(rowid);
// DELETE GRID LOCAL ROW
grid.delRowData(rowid);
$.jgrid.hideModal("#delmod"+grid_id,
{gb:"#gbox_"+grid_id,jqm:options.jqModal,onClose:options.onClose});
if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
// if after deliting there are no rows on the current page
// which is the last page of the grid
newPage--; // go to the previous page
}
// reload grid to make the row from the next page visable.
grid.trigger("reloadGrid", [{page:newPage}]);
}
return true;
},
processing:true
}
}
},
You can use "jqGridAddEditAfterComplete" event, which will be triggered after deleting of rows by delGridRow, or you can use "jqGridAfterDelRow" alternatively, because delGridRow calls delRowData internally and jqGridAfterDelRow will be triggered by delRowData.
For deleting row use below code snippet:
$('#gridId').jqGrid('delRowData',rowid);
$("#yourGridTable").jqGrid(
"navGrid",
"#yourGridTablePager",
{
del: true
},
{},
{},
{
// This event is fired when delete button is pressed in pager
//
beforeSubmit:function(){
console.log("After delete button of pager is clicked");
}
}
);

jqGrid getGridParam('colModel') missing information

I would like capture the colModel for my jqGrid when the page unloads and store it in session so the next time the user comes to the page it can be loaded automatically. But, the information returned by ('#contract_grid').getGridParam('colModel') is missing part or all of the information in searchoptions for the grid columns.
Any idea why this is or how to capture the full colModel? The grid works great on the initial load but without the other searchoptions params, the filter bar features/menus don't work when I refresh the page from the colModel stored in session.
Create the default colModel for the grid
var defaultColModel =
[
{name:'REQUESTID'
,index:'requestID'
,label:'Request ID'
,search:true
,stype:'text'
,width:75
,key:true
,hidden:false
},
{name:'REQUESTEDDATE'
,index:'requestedDate'
,label:'Request Date'
,sorttype:"date"
,search:true
,width:50
,searchoptions:{
dataInit:function(el){jQuery(el).daterangepicker(
{
arrows:false
, dateFormat:'yy-mm-dd'
, onClose: function(dateText, inst){ jQuery("#contract_grid")[0].triggerToolbar();}
, onOpen: function() {
jQuery('div.ui-daterangepickercontain').css({"top": jQuery('#mouseY').val() + 'px', "left": jQuery('#mouseX').val() + 'px' });
}
});
}
}
,hidden:false
},
{name:'BUSINESSOWNERPERSONID'
,index:'businessOwnerPersonID'
,label:'Business Owner'
,search:true
,stype:'select'
,width:100
,hidden:false
,searchoptions: {
dataUrl: 'cfc/com_common.cfc?method=getAjxPeople&role=businessOwnerPersonID',
buildSelect: function(resp) {
var sel= '<select><option value=""></option><option value="7583,1636">My Reports</option>';
var obj = $.parseJSON(resp);
$.each(obj, function() {
sel += '<option value="'+this['lk_value']+ '">'+this['lk_option'] + "</option>"; // label and value are returned from Java layer
});
sel += '</select>';
return sel;
},
dataEvents: [{
type: 'change',
fn: function(e) {
alert(this.value)
}
}]
}
}
];
When user navigates away from page, save the grid to session so it loads when they come back
$(window).on('beforeunload', function(){
takeSnapshot();
});
function takeSnapshot(){
var gridInfo = new Object();
gridInfo.colModel = jQuery('#contract_grid').getGridParam('colModel');
gridInfo.postData = jQuery('#contract_grid').jqGrid('getGridParam', 'postData');
var snapshotData = JSON.stringify(gridInfo);
$.ajax({
url: "actions/act_filter.cfc?method=takeSnapshot",
type: "POST",
async: false,
data: {gridName:'contract_grid'
,gridParamName:'contractGridParams'
,filterData:snapshotData
}
});
}
Create grid variable
var myGrid = jQuery("#contract_grid").jqGrid({
url: 'cfc/com_ajxRequestNew.cfc?method=getReqJSON&returnformat=json',
datatype: 'json',
postData: {filters: myFilters},
mtype: 'POST',
search: true,
colModel: defaultColModel,
altRows: true,
emptyrecords: 'NO CONTRACTS FOUND',
height: 400,
width: 1200,
sortname: lastSortName,
sortorder: lastSortOrder,
page: lastPage,
pager: jQuery('#report_pager'),
rowNum: lastRowNum,
rowList: [10,20,50,100],
viewrecords: true,
clearSearch: false,
caption: "Contracts Dashboard",
sortable: true,
shrinkToFit: false,
ajaxSelectOptions: {type: "GET"},
gridComplete: function() {
//set the selected toolbar filter values
var myFields = JSON.parse(myFilters);
//set fields in form at top. filter contains index value so get corresponding name value because its used in the column label #gs
if ( myFields['rules'].length > 0 ) {
for (var i=0; i < myFields['rules'].length; i++ ) {
$.each(defaultColModel, function(j) {
if(this.index == myFields['rules'][i]['field'] ) {
thisFieldName = this.name;
jQuery('#gs_' + thisFieldName).val( myFields['rules'][i]['data'] );
}
})
}
}
}
});
jQuery("#contract_grid").navGrid('#report_pager',{
edit:false,
add:false,
del:false,
search:false,
refresh:false
}).navButtonAdd("#report_pager",{ caption:"Clear",title:"Clear Filters", buttonicon :'ui-icon-trash',
onClickButton: function() {
jQuery.ajax({
url: "/assets/js/ajx_clearFilter.cfm?showHeader=0",
async: false,
type: "POST",
data: ({variableName:'session.contractGridParams'})
});
myGrid[0].clearToolbar();
}
}).navButtonAdd("#report_pager",{ caption:"Restore",title:"Restore Default Grid Columns and Filters", buttonicon :'ui-icon-refresh',
onClickButton: function() {
window.location = '?page=dsp_requestListingNew&clearSession=1';
}
}).navButtonAdd("#report_pager",{
caption: "Export",
title: "Export to Excel",
buttonicon :'ui-icon-document',
onClickButton: function(e){
jQuery("#contract_grid").jqGrid('excelExport',{url:'includes/act_requestListingExport.cfm'});
}
}).navButtonAdd("#report_pager",{
caption: "Columns",
buttonicon: "ui-icon-calculator",
title: "Select and Reorder Columns",
jqModal: true,
onClickButton: function(e){
$('#contract_grid').jqGrid('columnChooser', {
dialog_opts: {
modal: true,
minWidth: 470,
show: 'blind',
hide: 'explode'
}
});
}
}).navButtonAdd("#report_pager",{
caption: "Save",
title: "Save Snapshot",
buttonicon :'ui-icon-disk',
onClickButton: function(e){
takeSnapshot(0);
$('#fltrFrmLink').click();
}
});
jQuery("#contract_grid").jqGrid('filterToolbar', {
stringResult : true
, searchOnEnter : true
, autoSearch : true
, beforeClear : function() {
//set sortnames
var sn = jQuery("#contract_grid").jqGrid('getGridParam','sortname');
//set sort orders
var so = jQuery("#contract_grid").jqGrid('getGridParam','sortorder');
so = "desc";
//set grid params
jQuery("#contract_grid").jqGrid('setGridParam',{ sortorder:so, sortname:sn });
}
});
colModel returned by ('#contract_grid').getGridParam('colModel') on unload. searchoptions is missing everything for REQUESTEDDATE. Part of dataEvents and all of buildSelect are missing for BUSINESSOWNERPERSONID.
[{"name":"REQUESTID",
"index":"requestID",
"label":"Request ID",
"search":true,
"stype":"text",
"width":75,
"key":true,
"hidden":false,
"title":true,"lso":"",
"widthOrg":75,"resizable":true,"sortable":true},
{"name":"REQUESTEDDATE",
"index":"requestedDate",
"label":"Request Date",
"sorttype":"date",
"search":true,
"width":50,
"searchoptions:{},
"hidden":false,
"title":true,
"lso":"",
"widthOrg":50,
"resizable":true,
"sortable":true,"stype":"text"},
{"name":"BUSINESSOWNERPERSONID",
"index":"businessOwnerPersonID",
"label":"Business Owner",
"search":true,
"stype":"select",
"width":100,"hidden":false,
"searchoptions":{"dataUrl":"cfc/com_common.cfc?method=getAjxPeople&role=businessOwnerPersonID",
"dataEvents":[{"type":"change"}]},
"title":true,
"lso":"",
"widthOrg":100,
"resizable":true,
"sortable":true}]
JSON don't support serialization of functions. So the functions from searchoptions.dataInit, searchoptions.buildSelect and all other which you use in colModel will be discarded after you use JSON.stringify.
It's important to know which version of jqGrid/free jqGrid or Guriddo jqGrid JS you use. Starting with jqGrid 4.7 one can define template in colModel with string value (see the pull request). In the way you will have the main information in colModel which can be serialized using JSON.stringify.

Automatically cancelling jqgrid request

I'm aware of this answer: How do I add a cancel button to my jqgrid?, and I'm attempting to implement something similar, although without a button to trigger the cancel. Iv'e got a grid that loads on page load (a search that by default loads with no criteria) and I'd like to be able to cancel that default empty criteria search when the user actually executes a search with criteria. Since I don't need a button I'm trying to simplify the solution by merely keeping track of the xhr request in the loadBeforeSend method, and abort that xhr if it is not null as I load the grid. Code:
var gridXhr;
function getGridData() {
var searchParms = ...;
var colHeaders = [...];
var colDefinitions = [...];
if (gridXhr != null) {
alert(gridXhr.readyState);
gridXhr.abort();
gridXhr = null;
}
$('#grid').jqGrid('GridUnload');
$('#grid').jqGrid({
defaults: {...},
autowidth:true,
url: "<%= Page.Request.Path %>/ExecuteSearch",
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
postData: searchParms,
datatype: "json",
prmNames: {
nd: null,
rows: null,
page: null,
sort: null,
order: null
},
jsonReader: {
root: function (obj) { return obj.d; },
page: function (obj) { return 1; },
total: function (obj) { return (obj.d.length / 20); },
records: function (obj) { return obj.d.length; },
id: 'CatalogID',
cell: '',
repeatitems: false
},
loadonce: true,
colNames: colHeaders,
colModel: colDefinitions,
caption: "Search Results",
pager: 'searchPaging',
viewrecords: true,
loadBeforeSend: function (xhr) {
gridXhr = xhr;
},
loadError: function (xhr, status, error) {
gridXhr = null;
if (error != 'abort') {
alert("Load Error:" + status + "\n" + error);
}
},
loadComplete: function() {
gridXhr = null;
},
multiselect: <%= this.MultiSelect.ToString().ToLower() %>,
multiboxonly: true
}).setGridWidth(popWidth);
}
The problem I'm having is that subsequent executions of the jqGrid don't work. The loadError function is triggered, with an error (3rd parameter) of "abort." Do I need to do something more/different with the loadBeforeSend as done in the other answer?
Also, Oleg mentioned in his sample code myGrid[0].endReq(); and I can find no mention of that in the documentation - does that function exist?
If I understand you correctly you need just change the line
datatype: "json",
to something like
datatype: isSearchParamEmpty(searchParms) ? "local" : "json",
In other words you should create grid with datatype: "local" instead of datatype: "json" in case of empty searching criteria. The grid will stay empty.
Additionally you should consider to create jqGrid only once if colDefinitions and colHeaders will stay unchanged for different searching criteria. Instead of recreating of the grid you could change postData only and call trigger("reloadGrid").

jqgrid in mvc with multiple delete

i want to add multiple delete functionality in my Jqgrid with MVC here there is code for my current grid in Action there is two thing View and delete but i want a check box and out side the grid one button when click on it the checked item should be delete and also before delete action fire message for confirmation please help.
$(document).ready(function ()
{
#if (ViewBag.Filters != string.Empty)
{
#Html.Raw(ViewBag.Filters);
}
$("#jq-grid").jqGrid({
url: '/Home/GetList',//Service URL to fetch data
datatype: 'json',//Data Type which service will return
mtype: 'GET',
postData://Data that will be posted with every request
{
filters: function () {
return $.toJSON([
//Here add the parameters which you like to pass to server
{ Key: "EmployeeName", Value: $("#txtEmployeeName").val() },
{ Key: "Id", Value: $("#txtId").val() }
]);
}
},
colNames: ['Employee Id', 'EmployeeName','empPhoto', 'Action'],//Column Names
colModel: [//Column details
{ name: "Employee Id", index: "Employee Id", width: "220px" },
{ name: "Employee Name", index: "EmployeeName", width: "220px" },
{ name: "empPhoto", index: "empPhoto", width: "50px" ,formatter:imageFormat },
//Do not allow sorting on Action Column
{ name: "Action", index: "Action", sortable: false, width: "220px" }
],
autowidth: true,//Do not use auto width
sortname: '#ViewBag.EmployeeGridRequest.sidx',//This will persist sorting column
sortorder: '#ViewBag.EmployeeGridRequest.sord', // This will persist sorting order
imgpath: '',//if some images are used then show grid's path
caption: 'Employee Grid List',//Grid's Caption, you can set it to blank if you do not want this
scrollOffset: 0,
rowNum: #ViewBag.EmployeeGridRequest.rows, //Total Pages
page: #ViewBag.EmployeeGridRequest.page, // Current Page
rowList: [#ViewBag.EmployeeGridRequest.rowList], // Page Selection Options
viewrecords: true,
// height: "100%",
altRows: true,//Use alternate row colors
altclass: 'jqgaltrow',//Alternate row class
hoverrows: true, //Do not hover rows on mouse over
pager: $('#jq-grid-pager'),//Div in which pager will be displayed
toppager: true,
pgbuttons: true,//Show next/previous buttons
loadtext:'Loading Data please wait ...',
//loadui :'block',//enable by default, block will disable inputs, remove this line if you do not want to block UI
loadComplete: function (response) //Incase you want to perform some action once data is loaded
{
}
});
});
This is one approach that I took after finding no built in solution that jqgrid api provides. Hope this helps. I took this approach because I wanted to allow deletion of those records that passed business rules and to alert user of those records where problem was found.
#jqGrid delete button
//Delete selected devices from jqgrid standard checkbox
jQuery("#jqDevice").jqGrid('navButtonAdd', '#jqDevicePager', {
caption: "",
title: "Delete selected records",
buttonicon: "ui-icon-trash",
position: "first",
onClickButton: function(){
//alert("edit button clicked");
var selIds = $("#jqDevice").getGridParam("selarrrow");
var len = selIds.length;
$("#dialogDeleteConfirm").dialog({
buttons : {
"Confirm" : function() {
//loop through each rows selected and delete
if(selIds.length > 0){
for(var i = len - 1; i >= 0; i--) { //traverse the selarrow array in reverse order.
//alert("Deleting Device... " + selIds[i]); //Test
$.ajax({
type: 'POST',
data: "deviceID=" + selIds[i],
url: '/Device/DeleteDeviceByID',
async: false,
success: function(data, textStatus){
//successfully deleted row
$("#jqDevice").delRowData(selIds[i]);
alert("Successfully deleted records...");
},
error: function (jqXHR, textStatus, errorThrown) {
alert(JSON.parse(jqXHR.responseText));
}
});
}
}else{
alert("No rows selected.");
}
//Close Dialog after user confirms delete action
$(this).dialog("close");
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
}
});
# Controller Action
public ActionResult DeleteDeviceByID(int deviceID)
{
try
{
//update LastModBy before deleting
Device device = _deviceRepository.GetDevice(deviceID);
device.LastModBy = User.Identity.Name;
_deviceRepository.SaveChanges();
_deviceRepository.DeleteDevice(deviceID);
}
catch (Exception ex)
{
//throw new Exception (ex.Message.Replace(Environment.NewLine, string.Empty));
//return Json(new { success = false, message = ex.Message.Replace(Environment.NewLine, string.Empty) });
//Good way to raise error in JSON format
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json("There was a problem deleting ID - " + deviceID + " : " + ex.Message.Replace(Environment.NewLine, string.Empty) +
"\r\n\r\n Please try again. If the problem continues, please contact ... for further assistance.");
}
return Json(new { success = true });
}

Parameter Delete in jqGrid

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
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
});
}

Resources