Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

jquery - jqGrid, ASP.NET, JSON is Driving me crazy. Please Help

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: 'Submitter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

missing an identifier for that list:

return_value = {
    total:1,
    page:1,
    records:5,
    [{  .. some X12 messages  ..}]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...