jqGrid, ASP.NET, JSON is Driving me crazy. Please Help - asp.net
I've been trying to get this to work for days upon days and it seems like one thing after another. Initially, I finally tracked it down to trouble passing ASP.NET dates in the JSON string back to the grid. I am now using JSON.NET and the dates are coming back the way they should be I'm stuck right back where I alwasy seem to be. Here is my code, returned json string, and jqGrid code also: (I'm sorry it's so long, but I just didn't want to leave anything out in case that was the part that was screwing me up)! Basically, I am continually stuck in the success method of the ajax call where I try to addJSONData.... as of right now I am getting an error from Firebug that says:
invalid property id
({total:1,page:1,records:5,[{"ROWID":1,"...rName":"BCC","SubmitterID":"BCC4010","Su
ANY HELP WOULD BE SO GREATLY APPRECIATED! I Want to use this plug in so much, but I am going absolutely nuts trying to make it work!
Thanks in Advance, Briana :-)
WebMethod:
<WebMethod()> _
<Script.Services.ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json)> _
Public Function GetTableData() As String
Dim objController As New TradingPartnersController
Dim gv_page As String = String.Empty
Dim sidx As String = String.Empty
Dim sord As String = String.Empty
Dim start As String = String.Empty
Dim limit As String = String.Empty
Dim row As String = String.Empty
Dim header As String = String.Empty
Dim count As Integer = 0
Dim total_pages As Integer = 0
gv_page = HttpContext.Current.Request.Form("page") '.Form("page")
' get the requested page
limit = HttpContext.Current.Request.Form("rows")
' get how many rows we want to have into the grid
sidx = HttpContext.Current.Request.Form("sidx")
' get index row - i.e. user click to sort
sord = HttpContext.Current.Request.Form("sord")
' get the direction
If String.IsNullOrEmpty(sidx) Then
sidx = "PartnerID"
End If
If String.IsNullOrEmpty(sord) Then
sord = "ASC"
End If
If String.IsNullOrEmpty(limit) Then
limit = 10
End If
'' connect to the database
'GridView1.DataSource = objController.ListAll()
'GridView1.DataBind()
Dim objCollection As List(Of TradingPartnersInfo) = objController.ListAll()
count = objCollection.Count
If count > 0 Then
total_pages = Math.Ceiling(count / Int32.Parse(limit))
Else
total_pages = 0
End If
If gv_page Is Nothing Then
gv_page = 1
End If
If Not gv_page > total_pages Then
gv_page = total_pages
End If
start = Math.Ceiling(Int32.Parse(limit) * (Int32.Parse(gv_page) - Int32.Parse(limit)))
If start < 1 Then start = 1
Dim objPageCollection As List(Of TradingPartnersInfo) = objController.ListTradingPartners(sidx, sord, Int32.Parse(start), Int32.Parse(limit))
Dim json As New StringBuilder
json.Append("{")
json.Append("total:" & total_pages.ToString & ",")
json.Append("page:" & gv_page.ToString & ",")
json.Append("records:" & count.ToString & ",")
json.Append(JsonConvert.SerializeObject(objPageCollection))
json.Append("}")
Return json.ToString
End Function
Here is the jqGrid code:
jQuery('table.scroll').jqGrid({
jsonReader: {
root: "rows", //arry containing actual data
page: "page", //current page
total: "total", //total pages for the query
records: "records", //total number of records
repeatitems: false,
id: "ID" //index of the column with the PK in it
},
datatype: function(postdata) {
jQuery.jmsajax({
type: "POST",
url: "EDI.asmx",
method: "GetTableData",
dataType: "msjson",
data: {},
complete: function(data) {
var mygrid = jQuery('table.scroll')[0];
var result = (eval("(" + data.responseText + ")"));
var myjsongrid = (jeval(result.d));
alert(myjsongrid.rows);
mygrid.addJSONData(jeval(myjsongrid.rows)); //This is ERROR LINE
myjsongrid = null;
myjsongridParsed = null;
result = null;
},
success: function(data) {
alert('success: ' + data);
},
error: function(xhr) {
var res = xhr.responseText;
alert(res);
}
});
},
colNames: [
"ROWID",
"ID",
"PartnerID",
"Direction",
"InterchangeVersion",
"InterchangeSenderID",
"InterchangeReceiverID",
"ProductionMode",
"SubmitterName",
"SubmitterID",
"SubmitterPOC",
"CommQual",
"CommNumber",
"ReceiverName",
"ReceiverID",
"PartnerType",
"PartnerNotes",
"IncomingSP",
"OutgoingSP",
"ExchangeAck",
"isDeleted",
"DateTimeInserted",
"KeyID"
],
colModel: [
{ name: "ROWID",
width: 1,
hidden: true,
key: false,
sorttype: 'int',
editrules: { searchhidden: false,
hidedlg: true,
index: 'ROWID',
jsonmap: 'ROWID'
}
},
{ name: "ID",
width: 1,
hidden: true,
key: true,
sorttype: 'int',
editrules: { searchhidden: true,
hidedlg: false,
index: 'ID',
jsonmap: 'ID'
}
},
{ name: "PartnerID",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'PartnerID',
jsonmap: 'PartnerID',
label: 'PartnerID',
resizable: true,
search: true
}
},
{ name: "Direction",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'select',
editoptions: { value: "I:O" },
editrules: { required: true,
index: 'Direction',
jsonmap: 'Direction',
label: 'Direction',
resizable: true,
search: true
}
},
{ name: "InterchangeVersion",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'select',
editoptions: { value: "004010X098A1:004010X097A1:004010X096A1:004010X098A:004010X097A:004010X096A" },
editrules: { required: true,
index: 'InterchangeVersion',
jsonmap: 'InterchangeVersion',
label: 'InterchangeVersion',
resizable: true, search: true
}
},
{ name: "InterchangeSenderID",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'InterchangeSenderID',
jsonmap: 'InterchangeSenderID',
label: 'InterchangeSenderID',
resizable: true,
search: true
}
},
{ name: "InterchangeReceiverID",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'InterchangeReceiverID',
jsonmap: 'InterchangeReceiverID',
label: 'InterchangeReceiverID',
resizable: true,
search: true
}
},
{ name: "ProductionMode",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'select',
editoptions: { value: "T:P" },
editrules: { required: true,
index: 'ProductionMode',
jsonmap: 'ProductionMode',
label: 'ProductionMode',
resizable: true,
search: true
}
},
{ name: "SubmitterName",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'SubmitterName',
jsonmap: 'SubmitterName',
label: 'SubmitterName',
resizable: true,
search: true
}
},
{ name: "SubmitterID",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'SubmitterID',
jsonmap: 'SubmitterID',
label: 'SubmitterID',
resizable: true,
search: true
}
},
{ name: "SubmitterPOC",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'SubmitterPOC',
jsonmap: 'SubmitterPOC',
label: 'SubmitterPOC',
resizable: true,
search: true
}
},
{ name: "CommQual",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: "select",
editoptions: { value: "ED:EM:FX:TE" },
editrules: { required: false,
index: 'CommQual',
jsonmap: 'CommQual',
label: 'CommQual',
resizable: true,
search: true
}
},
{ name: "CommNumber",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: false,
index: 'CommNumber',
jsonmap: 'CommNumber',
label: 'CommNumber',
resizable: true,
search: true
}
},
{ name: "ReceiverName",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'ReceiverName',
jsonmap: 'ReceiverName',
label: 'ReceiverName',
resizable: true,
search: true
}
},
{ name: "ReceiverID",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: true,
index: 'ReceiverID',
jsonmap: 'ReceiverID',
label: 'ReceiverID',
resizable: true,
search: true
}
},
{ name: "PartnerType",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: "select",
editoptions: { value: "Clearinghouse:PPO:Both" },
editrules: { required: true,
index: 'PartnerType',
jsonmap: 'PartnerType',
label: 'PartnerType',
resizable: true,
search: true
}
},
{ name: "PartnerNotes",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'textarea',
editrules: { required: false,
index: 'PartnerNotes',
jsonmap: 'PartnerNotes',
label: 'PartnerNotes',
resizable: true,
search: true
}
},
{ name: "IncomingDataPrepSP",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: false,
index: 'IncomingDataPrepSP',
jsonmap: 'IncomingDataPrepSP',
label: 'IncomingDataPrepSP',
resizable: true,
search: true
}
},
{ name: "OutgoingDataPrepSP",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: 'text',
editrules: { required: false,
index: 'OugoingDataPrepSP',
jsonmap: 'OugoingDataPrepSP',
label: 'OutgoingDataPrepSP',
resizable: true,
search: true
}
},
{ name: "ExchangeAck",
width: 50,
resizable: true,
sortable: true,
sorttype: 'text',
editable: true,
edittype: "select",
editoptions: { value: "True:False" },
editrules: { required: true,
index: 'ExchangeAck',
jsonmap: 'ExchangeAck',
label: 'ExchangeAck',
resizable: true,
search: true
}
},
{ name: "isDeleted",
width: 5,
resizable: false,
sortable: true,
sorttype: 'text',
editable: true,
edittype: "select",
editoptions: { value: "Yes:No" },
editrules: { required: true,
index: 'isDeleted',
jsonmap: 'msg.d.isDeleted',
label: 'isDeleted',
resizable: true,
search: true
}
},
{ name: "DateTimeInserted",
width: 20,
hidden: false,
datefmt: 'Y-m-d',
sorttype: 'date',
editable: false,
editrules: { index: 'DateTimeInserted',
jsonmap: 'DateTimeInserted',
label: 'DateTimeInserted',
resizable: true,
search: true
}
},
{ name: "KeyID",
width: 5,
hidden: true,
key: false,
sorttype: 'int',
editrules: { index: 'KeyID',
jsonmap: 'KeyID',
hidedlg: true,
label: 'KeyID',
resizable: false,
search: false
}
}
],
height: 400,
shrinkToFit: true,
pager: jQuery('#pager'),
rowNum: 10,
rowList: [10, 20, 30, 40, 50],
sortname: 'ROWID',
sortorder: "asc",
viewrecords: true,
imgpath: 'http://localhost/DNN5/js/jQuery/jqGrid-3.4.3/themes/sand/images',
caption: 'X12 Trading Partners',
viewrecords: true,
gridComplete: function() {
alert("i'm grid complete" + JSON.stringify(msg));
//updates the new column order position
$('table.scroll').tableDnDUpdate();
}}).navGrid('table.scroll', { edit: true, add: true, del: true }).tableDnD();
Here is the Returned JSON String: (I have no problem seeing this data being returned to client.)
success:
{total:1,page:1,records:5,[{"ROWID":1,"ID":1,"PartnerID":"BCN","Direction":"I","InterchangeVersion":"004010X096A1","InterchangeSenderID":"BCC4010","InterchangeReceiverID":"company","ProductionMode":"T","SubmitterName":"BCC","SubmitterID":"BCC4010","SubmitterPOC":"BCC","CommQual":"","CommNumber":"","ReceiverName":"company","ReceiverID":"BCC4010","PartnerTypes":"","PartnerNotes":"","IncomingDataPrepSP":"","OutgoingDataPrepSP":"","ExchangeAck":false,"DateTimeInserted":new Date(1214412777787),"IsDeleted":false},{"ROWID":2,"ID":2,"PartnerID":"BCN","Direction":"I","InterchangeVersion":"004010X098A1","InterchangeSenderID":"BCC4010","InterchangeReceiverID":"company","ProductionMode":"T","SubmitterName":"BCC","SubmitterID":"BCC4010","SubmitterPOC":"BCC","CommQual":"","CommNumber":"","ReceiverName":"company","ReceiverID":"BCC4010","PartnerTypes":"","PartnerNotes":"","IncomingDataPrepSP":"","OutgoingDataPrepSP":"","ExchangeAck":false,"DateTimeInserted":new Date(1212088125000),"IsDeleted":false},{"ROWID":3,"ID":3,"PartnerID":"BCN","Direction":"O","InterchangeVersion":"004010X091A1","InterchangeSenderID":"HCA770385729","InterchangeReceiverID":"BCC47198 ","ProductionMode":"T","SubmitterName":"company Administrators","SubmitterID":"HCA770385729","SubmitterPOC":"briana","CommQual":"EM","CommNumber":"briana#company.com","ReceiverName":"BCN","ReceiverID":"BCC47198","PartnerTypes":"","PartnerNotes":"","IncomingDataPrepSP":"","OutgoingDataPrepSP":"","ExchangeAck":false,"DateTimeInserted":new Date(1212088125547),"IsDeleted":false},{"ROWID":4,"ID":4,"PartnerID":"EHG","Direction":"I","InterchangeVersion":"004010X097A1","InterchangeSenderID":"330989922","InterchangeReceiverID":"company","ProductionMode":"T","SubmitterName":"DENTALCONNECT","SubmitterID":"330989922","SubmitterPOC":"","CommQual":"","CommNumber":"","ReceiverName":"","ReceiverID":"","PartnerTypes":"Clearinghouse","PartnerNotes":"Dental clearinghouse. Sends billing address in the pay-to segment (NM1*87) and the service address in the billing segment (NM1*85).","IncomingDataPrepSP":"[dispatch].spPreprocessEHG","OutgoingDataPrepSP":"","ExchangeAck":true,"DateTimeInserted":new Date(1235603192033),"IsDeleted":false},{"ROWID":5,"ID":5,"PartnerID":"EMDEON","Direction":"I","InterchangeVersion":"004010X097A1","InterchangeSenderID":"341884003","InterchangeReceiverID":"857297703","ProductionMode":"T","SubmitterName":"INTERACTIVE PAYER NETWORK","SubmitterID":"341884003","SubmitterPOC":"","CommQual":"","CommNumber":"","ReceiverName":"","ReceiverID":"","PartnerTypes":"Clearinghouse","PartnerNotes":"Dental clearinghouse. Sends billing address in the pay-to segment (NM1*87) and the service address in the billing segment (NM1*85).","IncomingDataPrepSP":"","OutgoingDataPrepSP":"","ExchangeAck":true,"DateTimeInserted":new Date(1235603192000),"IsDeleted":false}]}
Actually, tvanfosson makes an excellent point with the requirement of the 'rows' identifier. I'm unfamiliar with jMSAjax so my comments may be null and void. I'm glad to be aware of it.
Could it be something as simple as the return type being string? That is, when the response is evaluated, you end up with the encapsulated string not the json object.
I've been in a similar place myself. I found the options to be either, create a business object that represents the expected jqGrid response and return the object not a string (ASP.NET will serialize it as JSON for you!) or modify the jqGrid to eval the response twice (messy).
missing an identifier for that list:
return_value = {
total:1,
page:1,
records:5,
[{ .. some X12 messages ..}]
}
I have spent a lot of time trying to get jqGrid to work with ASP.NET using JSON. Now that I have it working, I would like to share it with you. Hoping to save time for other people.
I found the answer here. This is not to say there are no other ways to make this work (I'm sure there are). But this one definitely works.
To summarize the things that made a difference for me:
Using "datatype: function() {" on the settings of the jqGrid, and NOT using "datatype: json". The function uses "$.ajax(" to call the service. Looking in Fiddler, this changed the data coming back to the browser, to be pure JSON (instead of JSON wrapped in XML).
Using a web service that returns a
data class (in the schema jqGrid
expects). I first tried using JSON.NET
but for some reason the message
showed (in Fiddler again) to be
escaped with \ for every quote in the
string. I'm pretty sure you can get
JSON.NET to work. But it works just
as well without it.
It doesn't look like you are adding the rows property identifier. Try changing:
json.Append(JsonConvert.SerializeObject(objPageCollection))
to
json.Append("rows: " + JsonConvert.SerializeObject(objPageCollection))
If this doesn't work, I suggest that you simplify the problem -- reduce the data to one row, for example -- and see if you can get it working with simpler data, then gradually add more stuff back into it.
Related
How to delete multiples registers in jqgrid using asp.net mvc?
Could you please help me how I could do to delete multiple records selected in my jqgrid? I've tried a number of ways, but so far not got any success. I will be grateful to anyone who can help me. jQuery("#grid-table").jqGrid({ //direction: "rtl", url: "/Lojas/GetLojas", datatype: 'json', mtype: 'Get', height: '100%', colNames: [ ' ', 'Name', 'Description' ], colModel: [ { name: 'myac', index: '', width: 65, fixed: true, sortable: false, resize: false, formatter: 'actions', formatoptions: { keys: true, delOptions: { recreateForm: true, url: '/Lojas/Delete', beforeShowForm: beforeDeleteCallback }, editformbutton: true, editOptions: { recreateForm: true, url: '/Lojas/Edit', closeAfterEdit: true, beforeShowForm: beforeEditCallback, closeOnEscape: true } } }, { key: true, hidden: true, name: 'Id', index: 'Id', sorttype: "int", editable: false }, { key: false, name: 'Name', index: 'Name', editable: true}, { key: false, name: 'Description', index: 'Description', editable: true} ], viewrecords: true, loadonce: true, rowNum: 10, rowList: [5, 10, 15], jsonReader: { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, Id: "0" }, pager: pager_selector, altRows: true, autowidth: true, multiselect: true, multiboxonly: true, sortorder: "desc", multiboxonly: true, caption: "Lojas Cadastradas" }); //navButtons jQuery("#grid-table").jqGrid('navGrid', pager_selector, { edit: true, add: true, del: true, search: true, refresh: true, view: true, }, { url: '/Lojas/Edit', closeOnEscape: true, closeAfterEdit: true, recreateForm: true }, { url: '/Lojas/Create', closeOnEscape: true, closeAfterAdd: true, recreateForm: true }, { url: '/Lojas/Delete', closeOnEscape: true, closeAfterDelete: true, recreateForm: true }, { //search form recreateForm: true, closeOnEscape: true, closeAfterSearch: true, multipleSearch: true }, { //view record form recreateForm: true } ) Code in my controller: public ActionResult Delete(Loja loja) { Loja lojaToDelete = db.Lojas.Find(loja.Id); if (lojaToDelete == null) { return HttpNotFound(); } db.Lojas.Remove(lojaToDelete); db.SaveChanges(); return View(loja); }
I recommend you to change prototype of Delete function public ActionResult Delete(Loja loja) to public void Delete(string id) The main problem in your code is the following. Corresponds to the documentation jqGrid post id parameter to url: '/Lojas/Delete'. You can rename the name of id parameter using prmNames. In the case you can use prmNames: {id: "Id"}, but it's not really required. If multiple rows needed be deleted then id string will be comma separated and you can use something like public void Delete(string id) { var ids = id.Split(','); foreach (lojaId in ids) { Loja lojaToDelete = db.Lojas.Find(lojaId); if (lojaToDelete == null) throw new HttpResponseException(HttpStatusCode.NotFound); db.Lojas.Remove(lojaToDelete); } db.SaveChanges(); }
Jqgrid filter is not working with Dropdownlist in Asp.net
hii Guys !! I implemented filter with dropdownlist in jqgrid but grid is not showing the values of the column on which i added filter neither is filtering the data.. Here is my code... <script type="text/javascript"> var categoriesStr = ":All;1:vikas;2:Ankur"; $(function () { $("#UsersGrid").jqGrid({ url: 'getGriddahico.ashx', datatype: 'json', height: 250, colNames: ['UserID', 'UserName', 'FirstName', 'MiddleName', 'LastName', 'EmailID'], colModel: [ { name: 'UserID', index: 'UserID', width: 100, sortable: true, align: 'center' }, { name: 'UserName', width: 100, sortable: true, align: 'center' , formatter: 'select', stype: 'select', sorttype: function (cell) { return categories[cell]; }, edittype: 'select', editoptions: { value: categoriesStr }, searchoptions: { sopt: ['eq'] } }, { name: 'FirstName', width: 100, sortable: true, align: 'center' }, { name: 'MiddleName', width: 100, sortable: true }, { name: 'LastName', width: 100, sortable: true, align: 'center' }, { name: 'EmailID', width: 150, sortable: true, align: 'center' } ], rowNum: 10, rowList: [10, 20, 30], pager: '#UsersGridPager', sortname: 'UserID', loadonce: true, viewrecords: true, ignorecase:true, sortorder: 'asc', autowidth: true, toppager: true, height: '100%' }); $("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false, search: false }); $("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn", beforeSearch: function () { //alert("verifying the data"); var postData = grid.jqGrid('getGridParam', 'postData'); // we use `stringResult: true` so decoding of the search parameters are a little complex var searchData = jQuery.parseJSON(postData.filters); for (var iRule = 0; iRule < searchData.rules.length; iRule++) { if (searchData.rules[iRule].field === "UserName") { var valueToSearch = searchData.rules[iRule].data; if (valueToSearch.length != 5) { alert("The search string MUST de 5 charachters length!"); return true; // error } } } return false; } }); //jQuery("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false }); }); </script> Anyhelp will be welcomed ... Thanx in advance
May be getGriddahico.ashx is not returning sorted values. if u could share the code of getGriddahico.ashx, it would be better.
jqGrid: How To Delete Row/s From "navButtonAdd" And "delGridRow"?
I've encountered a problem with jqGrid datagrid. I need to delete one row or more with a button "Delete". Here my code: $grid.navGrid('#pager', { edit: false, add: false, del: false, search: false }); $grid.navButtonAdd('#pager', { caption: "Delete", buttonicon: "ui-icon-del", position: "last", onClickButton: function() { alert("Deleting Row"); row_ids = $grid.getGridParam('selarrrow'); $grid.delGridRow(row_ids, { dataType: 'json', mtype: 'GET', url: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&action=record_delete'; ?>' }); } }); This snippet of code send to the "url:" option the id/s of selected row/s (it works). That url return a response, in json format.. This answer say if the operation was successful or not. I need to display an alert with that message, how do I do? And, another problem, when I click on "Delete" button (on bottom of the jqGrid), it displays an ajax windows with the question "Do you want to delete selected items?", with the "Yes" input and the "No" input. When I click "Yes", this ajax window will not close! Thank you! Dante EDIT [1] && [2] $(document).ready(function() { $grid = $("#list"); fixPositionsOfFrozenDivs = function() { if (typeof this.grid.fbDiv !== "undefined") { $(this.grid.fbDiv).css($(this.grid.bDiv).position()); } if (typeof this.grid.fhDiv !== "undefined") { $(this.grid.fhDiv).css($(this.grid.hDiv).position()); } }; $grid.jqGrid({ url: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&option=get_records'; ?>', datatype: 'json', mtype: 'GET', height: 'auto', width: window.innerWidth-35, //width: '1225', colNames: ['ID', 'Column A', 'Column B', 'Column C', 'Column D'], colModel: [ { name: 'id', index: 'id', width: 130, align: 'center', search: true, sortable: true, frozen: true, editable: true, edittype: 'text', formatter: 'showlink', editoptions: { size: 130, maxlength: 50 }, stype: 'text' }, { name: 'col_a', index: 'col_a', width: 250, align: 'left', search: true, sortable: true, frozen: false, editable: true, edittype: 'text', editoptions: { size: 250, maxlength: 40 }, stype: 'text' }, { name: 'col_b', index: 'col_b', width: 120, align: 'left', search: true, sortable: true, frozen: false, editable: true, edittype: 'text', editoptions: { size: 120, maxlength: 40 }, stype: 'text' }, { name: 'col_c', index: 'col_c', width: 100, align: 'right', search: true, sortable: true, frozen: false, editable: true, edittype: 'text', editoptions: { size: 100, maxlength: 40 }, stype: 'text' }, { name: 'col_d', index: 'col_d', width: 100, align: 'right', search: true, sortable: true, frozen: false, editable: true, edittype: 'text', editoptions: { size: 100, maxlength: 6 }, stype: 'text' } ], caption: 'Objects', pager: '#pager', sortname: 'id', sortorder: 'ASC', rowNum: 25, rowList: [25, 50, 100, 200, <?php echo $totrecords; ?>], loadonce: true, gridview: true, viewrecords: true, rownumbers: true, rownumWidth: 40, toppager: true, multiselect: true, autoencode: true, ignoreCase: true, shrinkToFit: false, loadComplete: function() { $("option[value=<?php echo $totrecords; ?>]").text('All'); }, editurl: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&option=delete_records'; ?>' }); $grid.jqGrid('filterToolbar', {multipleSearch: false, stringResult: false, searchOnEnter: false, defaultSearch: 'cn'}); $grid.navGrid('#pager', { edit: false, add: false, del: false, search: false }); $grid.navButtonAdd('#pager', { caption: "Delete", buttonicon: "ui-icon-del", position: "last", onClickButton: function() { row_ids = $grid.getGridParam('selarrrow'); $grid.delGridRow(row_ids, { closeOnEscape: true, mtype: 'POST', afterSubmit: function(data_from_server, array_data) { var result = data_from_server.responseText; var message = eval('(' + result + ')'); alert(message.query); } }); } }); $grid.jqGrid('setFrozenColumns'); $grid[0].p._complete.call($grid[0]); fixPositionsOfFrozenDivs.call($grid[0]); });
You should be able to use the afterSubmit event to display your message. From the jqGrid documentation: afterSubmit fires after response has been received from server. Typically used to display status from server (e.g., the data is successfully deleted or the delete cancelled for server-side reasons). Receives as parameters the data returned from the request and an array of the posted values of type id=value1,value2. When used this event should return array with the following items [success, message] where success is a boolean value if true the process continues, if false a error message appear and all other processing is stopped. afterSubmit : function(response, postdata) { … return [succes,message] } Regarding your second problem, I am not sure why the Ajax window will not close. Have you debugged the code to see if you are receiving a JavaScript error at that time? If not, it may be necessary for you to post a small example demonstrating the problem.
It's not good to use HTTP GET for delete operation. Do you want that the previous server response on the same URL will be cached and not send to the server? Default value of mtype is 'POST'. If you have RESTfull services on the server side you will need to use mtype: 'DELETE', but the usage of 'GET' can have sense only for the some dummy code which don't delete anything on the server. Moreover you use dataType: 'json' parameter which is not exist for delGridRow (see the documentation). Even if you would use ajaxDelOptions: { datyType: "json" } you will get the server response (see the answer of Justin) not automatically converted from JSON to object. The reason is that the current code of delGridRow use complete callback instead of success callback (see here). So if you get JSON response from the server you will have to call $.parseJSON explicitly inside of afterSubmit callback (see the Justin's answer).
JQGrid create dropdown cell with values depended from row id
I have the following JQgrid which is working fine. $("#Groups_UseCases_Grid").jqGrid({ url: 'groupsHandler.ashx?mod=3', datatype: 'json', mtype: 'GET', loadonce: true, height: 'auto', width:'750px', colNames: ['id', 'groupname', 'workSpace'], colModel: [ { name: 'id', index: 'id', key:true, width: 200, sortable: false, editoptions: {readonly: true,size: 10}}, { name: 'groupname', width: 200, sortable: false, editable:false }, { name: 'workSpace', width: 400, sortable: false, editable:true , edittype:"select",editoptions:{multiple:true, size:"<%=combolistSize%>", value:"<%=combolist%>"} } ], rowNum: 30, rowList: [30, 60, 90], pager: '#pager', sortname: 'id', viewrecords: true, sortorder: 'asc', caption: 'Groups UseCases Ascosiation Grid', editurl: 'groupsHandler.ashx?mod=3', hidegrid: false, altRows:false, altclass:'myAltRowClass', grouping:true, groupingView : { groupField : ['useCase'], groupText : ['<b> useCase : {0} (Records {1}) </b>'] } }); jQuery("#Groups_UseCases_Grid").jqGrid('navGrid',"#pager", {edit:false,add:false,del:false}); jQuery("#Groups_UseCases_Grid").jqGrid('inlineNav',"#pager", {edit:true,add:false,del:false}, {afterSubmit: function(rowid, aData){document.forms[1].submit();//alert("row id is "+rowid) }}, {closeAfterEdit: true,reloadAfterSubmit: false}, {closeAfterAdd: true,reloadAfterSubmit: false}, {reloadAfterSubmit: true}); C# code : private string combolist; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { combolist =create_combolist(); } } private string create_combolist(/string groupID/) {.....} My problem is that i want column workSpace values to be generated by giving the id of the selected row as it depends on it and narrows the dropdown valuelist Is it possible using the onSelectRow? I tried onSelectRow: function(id){<%usecasesample.create_combolist(); <%combolist = usecasesample.create_combolist();%>; } , that works too but i cant supply row id in it. Any help appreciated, thanks in advance, alex
This seems to work fine $("#Groups_UseCases_Grid").jqGrid({ url: 'groupsHandler.ashx?mod=2', datatype: 'json', mtype: 'GET', loadonce: true, height: 'auto', width:'850px', colNames: ['groupid', 'groupname', 'workspaces'], colModel: [ { name: 'groupid', index: 'id', key:true, width: 200, sortable: false, editoptions: {readonly: true,size: 10}}, { name: 'groupname',index: 'groupname', width: 200, sortable: false, editable:false }, { name: 'workspaces', width: 400, sortable: false, editable:true , edittype:"select",editoptions:{multiple:true, size:"" }} ], onSelectRow: function(id) { var name='workspaces'; jQuery("#Groups_UseCases_Grid").setColProp(name, { editoptions: {multiple:true, dataUrl: 'groupsHandler.ashx?mod=3&rowID='+id }}) }, rowNum: 30, cellEdit:false, rowList: [30, 60, 90], pager: '#pager', sortname: 'id', viewrecords: true, sortorder: 'asc', caption: 'Groups UseCases Ascosiation Grid', editurl: 'groupsHandler.ashx?mod=2&rows=20&page=1', hidegrid: false, altRows:false, altclass:'myAltRowClass', grouping:true, groupingView : { groupField : ['useCase'], groupText : [' useCase : {0} (Records {1}) '] } }); jQuery("#Groups_UseCases_Grid").jqGrid('navGrid',"#pager", {edit:false,add:false,del:false}); jQuery("#Groups_UseCases_Grid").jqGrid('inlineNav',"#pager", {edit:true,add:false,del:false}, {afterSubmit: function(rowid, aData){document.forms[1].submit();//alert("row id is "+rowid) }}, {closeAfterEdit: true,reloadAfterSubmit: false}, {closeAfterAdd: true,reloadAfterSubmit: false}, {reloadAfterSubmit: true});
I could not able to see Add. Edit, Delete and View using JQGrid
I have jQuery(document).ready(function () { jQuery("#list").jqGrid({ url: '/TabMaster/GetGridData', datatype: 'json', mtype: 'GET', colNames: ['col ID', 'First Name', 'Last Name', '', '', '', ''], colModel: [ { name: 'colID', index: 'colID', width: 100, align: 'left' }, { name: 'FirstName', index: 'FirstName', width: 150, align: 'left' }, { name: 'LastName', index: 'LastName', width: 300, align: 'left' }, { name: 'add', width: 18, sortable: false, search: false, formatter: function () { return "<span class='ui-icon ui-icon-plus'></span>" } }, { name: 'edit', width: 18, sortable: false, search: false, formatter: function () { return "<span class='ui-icon ui-icon-pencil'></span>" } }, { name: 'del', width: 18, sortable: false, search: false, formatter: function () { return "<span class='ui-icon ui-icon-trash'></span>" } }, { name: 'details', width: 18, sortable: false, search: false, formatter: function () { return "<span class='ui-icon ui-icon-document'></span>" } } ], onSelectRow: function (rowJsonId) { handleSelectedRow(rowJsonId); }, pager: jQuery('#pager'), rowNum: 4, rowList: [1, 2, 4, 5, 10], sortname: 'colID', sortorder: "asc", viewrecords: true, gridview: true, rownumbers: true, multiselect: true, imgpath: '/scripts/themes/steel/images', caption: 'Tab Master Information' }).navGrid(pager, { edit: true, add: true, del: true, refresh: true, search: true }); }); function handleSelectedRow(thing) { } but i could not able to see buttons for Add, Edit, Delete and View i am only able to see for empty column in JQGrid. for your reference Please provide your valuable comments for the same.
It seems to me that you try to use my demo from the answer: All classes for the ui-icon-plus, ui-icon-trash and so on come from jQuery UI CSS. You shoul just verify that you included jQuery UI correctly together with the images subdirectory.