Hi All,
I am new bee in the JqGrid.... I have one requirement I need one JQGrid with the customized columns means in each row I have some check boxes, textboxes and text area...... Now the thing is I am able to load my JqGrid properly,,, but the problem is how to save this jqgrid into db,, means I need the values of JqGrid on VB page by ajax Call.
Here is my code
function AssayPageBatchAndSample() {
// BatchQCGrid
// StainAcceptedGridView
var accessionId = $("[id*='AccessionIDhidden']").val();
$("#BatchQCGrid").jqGrid({
datatype: 'json',
colNames: ['Batch ID:"' + accessionId + '"', 'Pos QC', 'Neg QC', 'Pass', 'Fail', 'Repeat?', 'Comments'],
colModel: [
{ name: 'Assay', index: 'Assay',width:50},
{ name: 'PosQC', index: 'PosQC', width: 50 },
{ name: 'NegQC', index: 'NegQC', width: 50 },
{ name: 'Pass', index: 'Pass', formatter: showPassCheckbox, width: 50 },
{ name: 'Fail', index: 'Fail', formatter: showFailCheckbox, width: 50 },
{ name: 'Repeat', index: 'Repeat', formatter: showRepeatCheckbox, width: 50 },
{ name: 'Comments', index: 'Comments', formatter: cmntBatchQcComments, Width:300 }
],
multiselect: false,
emptyrecords: "No records to view",
pgbuttons: false,
viewrecords: true,
loadonce: true,
altRows: true,
height: 'auto'
});
dArray = "{";
dArray += "'caseNo': '" + caseno + "',";
dArray += "'rqstMsg': '" + hdnsession + "'";
dArray += "}";
$.ajax({
type: "POST",
url: "../../../../ClientSide-Services/Assay.asmx/GetBatchQcData",
data: dArray,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(response) {
if (response.d != '{"Table" : ]}') {
var gd = eval('(' + response.d + ')');
for (row in gd) {
$("#BatchQCGrid").jqGrid('addRowData', row, gd[row]);
}
$("#BatchQCGrid").trigger("reloadGrid");
}
else {
$("#BatchQCGrid").jqGrid("clearGridData", true).trigger("reloadGrid");
}
},
error: function(response) {
alert(response.responseText);
}
});
$('[id*="InputToolbarSave"]').click(function() {
alert("In Save button assay");
var gridData = jQuery("#BatchQCGrid").getRowData();
var postData = JSON.stringify(gridData);
alert("JSON serialized jqGrid data:n" + postData);
$.ajax({
type: "POST",
url: preFixUrl + "ClientSide-Services/Common_WS.asmx/Test",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{ gridData: '" + postData + "' }",
async: false,
success: function() {
},
error: function(response) {
alert(response.responseText);
}
});
});
} //End
function showPassCheckbox(cellValue, options, rowobject, action) {
var a = "<input type='checkbox' id='chkPasscheckbox' ></input>";
return a;
}
function showFailCheckbox(cellValue, options, rowobject, action) {
var a = "<input type='checkbox' id='chkFailcheckbox'></input>";
return a;
}
function showRepeatCheckbox(cellValue, options, rowobject, action) {
var a = "<input type='checkbox' id='chkRepeatcheckbox'></input>";
return a;
}
function cmntBatchQcComments(cellValue, options, rowobject, action) {
return "<textarea rows='5' cols='20' id='BatchQcComments' >" +rowobject.Comments+ "</textarea>";
}
************************asmx.vb page **********************************************************
<WebMethod()> _
Public Function GetBatchQcData(ByVal rqstMsg As String, ByVal caseNo As String) As String
Try
Dim bs As New BatchingService.Batching
Dim os As New OrderingService.Ordering
Dim batchData As DataSet
rqstMsg = Decrypt(rqstMsg)
Dim apCase As OrderingService.ApCase = os.ApCase_Get(caseNo, False, rqstMsg)
batchData = bs.BatchQC_Get(apCase.TestOrders(0).Batch.ID, rqstMsg)
Return Common.GetJSONString(batchData.Tables(0))
Catch ex As Exception
Throw (ex)
End Try
End Function
<WebMethod()> _
Public Function Test(ByVal gridData As String)
Try
Dim testData As Object = New JavaScriptSerializer().Deserialize(Of Object)(gridData)
Catch ex As Exception
Throw (ex)
End Try
End Function