Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


XML
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 **********************************************************
VB
<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 jsonSerializer As New JavaScriptSerializer()
            'Dim testData As Object
            'testData = CType(jsonSerializer.Deserialize(gridData), Object)
            Dim testData As Object = New JavaScriptSerializer().Deserialize(Of Object)(gridData)

        Catch ex As Exception
            Throw (ex)
        End Try
    End Function
Posted
Updated 17-Feb-14 1:23am
v2

1 solution

try this ,

C#
colNames: ['Prod Code', 'Product#', 'Status'],
            colModel: [
             {
                 name: 'ProductCode', index: 'pCode', search: true, searchoptions: {}, width: 100, resizable: true, firstsortorder: 'desc',
                 formatter: 'dynamicLink',
                 formatoptions: {
                     url: function (cellvalue, rowId, rowData) {
                         return '/xyz/abc/?p_li=' + '@ViewBag.token' + '&p_iid=' + rowData[6];
                     }
                 }
             },
            { name: 'ProductName', index: 'pName', width: 100, resizable: false, firstsortorder: 'desc' },
            { name: 'status', index: 'status', width: 100, resizable: false, firstsortorder: 'desc' },



good luck
Naufal
 
Share this answer
 
Comments
Ambivert 17-Feb-14 7:51am    
@Naufel Basheer thanks fro the reply Naufel, I want to take checkboxes and text area....... can you please be more specific regarding your answer I did not get it....
Naufel Basheer 17-Feb-14 7:54am    
in this grid , my first Colum ('ProductCode')will have hyperlink , which will make an ajax call, and will show further details about the selected product ,
there is no text box in this code snip.
Ambivert 17-Feb-14 8:01am    
My requirement is to save all the data which is filled in JqGrid ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900