0

这几天我一直在搞砸这件事,我正在失去理智。我能够让 jqGrid 工作,使用“本地”数据类型,现在我正试图将它与我的 SQL 数据联系起来。我没有错误,只是一个空白网格。我在网上搜索并尝试了许多没有运气的例子。网格显示和列​​标题出现,只是没有数据。我也没有收到任何 js 错误。在这一点上,我对分页、排序、搜索等不感兴趣。只需要获取数据显示。有人可以指出我正确的方向吗?

VB.NET code:
============
Public Function GetGridData() As JqGridData
    Dim sql As String = "Select unit_number, product_code, blood_type, 'No Match' scan_result From product_header Where (product_id < 20) Order By 1, 2, 3"

    Dim dt As New DataTable()
    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn").ConnectionString)
    Dim adapter As New SqlDataAdapter(sql, conn)
    adapter.Fill(dt)

    Dim result As New JqGridData()
    Dim gridRows As New List(Of TableRow)()
    Dim idx As Integer = 1

    For Each row As DataRow In dt.Rows
        Dim newrow As New TableRow()
        newrow.id = idx
        newrow.cell = New List(Of String)(4)
        newrow.cell(0) = row(0).ToString()
        newrow.cell(1) = row(1).ToString()
        newrow.cell(2) = row(2).ToString()
        newrow.cell(3) = row(3).ToString()
        gridRows.Add(newrow)
    Next

    result.total = 2
    result.page = 1
    result.records = gridRows.Count
    result.rows = gridRows

    Return result
End Function

Public Class TableRow

    Private m_id As Integer
    Private m_cell As List(Of String)

    Public Property id() As Integer
        Get
            Return m_id
        End Get
        Set(ByVal value As Integer)
            m_id = value
        End Set
    End Property

    Public Property cell() As List(Of String)
        Get
            Return m_cell
        End Get
        Set(ByVal value As List(Of String))
            m_cell = value
        End Set
    End Property

End Class

Public Class JqGridData

    Private m_total As Integer
    Private m_page As Integer
    Private m_records As Integer
    Private m_rows As List(Of TableRow)

    Public Property total() As Integer
        Get
            Return m_total
        End Get
        Set(ByVal value As Integer)
            m_total = value
        End Set
    End Property

    Public Property page() As Integer
        Get
            Return m_page
        End Get
        Set(ByVal value As Integer)
            m_page = value
        End Set
    End Property

    Public Property records() As Integer
        Get
            Return m_records
        End Get
        Set(ByVal value As Integer)
            m_records = value
        End Set
    End Property

    Public Property rows() As List(Of TableRow)
        Get
            Return m_rows
        End Get
        Set(ByVal value As List(Of TableRow))
            m_rows = value
        End Set
    End Property

End Class

js code:
========
$(document).ready(function(){
    $("#list").jqGrid({
        url: 'Display.aspx/GetGridData',
        datatype: 'json',
        mtype: "GET",
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        serializeGridData: function (data) {
            return JSON.stringify(data);
        },
        jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: true
        },
        colModel: [
            {name: 'unit_number', label: 'Unit Number', width: 100, align: 'center'},
            {name: 'product_code', label: 'Product Code', width: 200, align: 'center'},
            {name: 'blood_type', label: 'Blood Type', width: 200, align: 'center'},
            {name: 'scan_result', label: 'Scan Result', width: 200, align: 'center'}
        ],
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: 'id',
        sortorder: "asc",
        pager: "#pager",
        viewrecords: true,
        caption:  'My first grid'
    }).jqGrid('navGrid', '#pager', {edit: false, add: false, del: false, search: true});
});
4

1 回答 1

0

尝试拔出

    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    serializeGridData: function (data) {
        return JSON.stringify(data);
    },
    jsonReader: {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: true
    },

并确保您传递 jqGrid 需要的所有数据。我不是 VB.Net 的人,所以我假设您有一个控制器/动作为您的网格提供数据?您也可以尝试手动为网格构建一行以测试该方面。

于 2013-03-13T00:39:46.520 回答