【问题标题】:FlexiGrid "No Items", response clearly shows dataFlexiGrid“无项目”,响应清楚地显示数据
【发布时间】:2013-01-10 18:29:13
【问题描述】:

表格可见,看起来不错,列标题出现,但在“处理中,请稍候...”的瞬间后,状态变为“无项目”。检查 DOM 中的响应显示数据正在从 Web 服务正确返回,格式如下:

<?xml version="1.0" encoding="utf-8"?>
<MyDataClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <Page>1</Page>
  <Rows>
    <MyDataRow>
      <request_id>13073</request_id>
      <status>501</status>
      <req_by_user_id>herbjm</req_by_user_id>
    </MyDataRow>
    ...
    ....
  </Rows>
</MyDataClass>

这里是有问题的 flexigrid javascript:

$('#report').flexigrid({
    url: 'reportdata.asmx/rptPendingServerRequestsFlexi',
    dataType: 'xml',
    colModel: [
        { display: 'ID', name: 'request_id', width: 40, sortable: true, align: 'center' },
        { display: 'Status', name: 'status', width: 180, sortable: true, align: 'left' },
        { display: 'Requested By', name: 'req_by_user_id', width: 120, sortable: true, align: 'left' }
    ],
    searchitems: [
        { display: 'ID', name: 'request_id' },
        { display: 'Status', name: 'status', isdefault: true },
        { display: 'Requested By', name: 'req_by_user_id' }
    ],
    sortname: "request_id",
    sortorder: "desc",
    usepager: false,
    title: 'Server Requests',
    useRp: false,
    rp: 30,
    showTableToggleBtn: false,
    singleSelect: true
});

对于奖励积分,即使分页被禁用,我如何显示页脚?

更新:我为 flexigrid 演示检查了 DOM,以下是他们返回的 XML 的格式:

<?xml version="1.0" encoding="utf-8"?>
<rows>
    <page>1</page>
    <total>239</total>
    <row id='1'>
        <cell>1</cell>
        <cell>501</cell>
        <cell>Steve</cell>
    </row>
    <row id='2'>
        <cell>2</cell>
        <cell>501</cell>
        <cell>Fred</cell>
    </row>
</rows>

我猜这就是为什么它不起作用?要了解我是如何构建响应的,请查看以下问题:vb.net return json object with multiple types?

【问题讨论】:

    标签: jquery ajax vb.net flexigrid


    【解决方案1】:

    根据我在here 和其他几个位置找到的各种信息,flexigrid 要求 XML 具有特定格式:

    rows - the row definition
      page - the current page number
      total - the total count of rows in this collection
      row - the row, with a unique property called id
        cell - each row must contain cells in the order that they are displayed on the grid
    

    由于 MyDataClass 是由 your previous question 生成的,以下是这些类的更新版本,它们将产生所需的输出:

    <XmlType("rows")> _
    Public Class MyDataClass
    
        <XmlElement("page")> _
        Public Property Page As Integer
    
        <XmlElement("total")> _
        Public ReadOnly Property Total As Integer
            Get
                If Me.Rows IsNot Nothing Then
                    Return Me.Rows.Count
                Else
                    Return 0
                End If
            End Get
        End Property
        <XmlElement("row")> _
        Public Property Rows As List(Of MyDataRow)
    
        ' Parameterless constructor to support serialization.
        Public Sub New()
            Me.Rows = New List(Of MyDataRow)
        End Sub
        Public Sub New(wPage As Integer, ds As DataSet)
            Me.New()
    
            Me.Page = wPage
    
            For Each oRow As DataRow In ds.Tables(0).Rows
                Dim oMyRow As New MyDataRow
    
                oMyRow.Id = CInt(oRow("id"))
                oMyRow.Name = CStr(oRow("Name"))
    
                Me.Rows.Add(oMyRow)
            Next
    
        End Sub
    End Class
    
    <XmlType("row")> _
    Public Class MyDataRow
        <XmlAttribute("id")> _
        Public Property Id As Integer
    
        Private m_cCells As List(Of MyDataCell)
    
        <XmlIgnore()> _
        Public WriteOnly Property Name As String
            Set(value As String)
                Me.AddCell("Name", value)
            End Set
        End Property
    
        <XmlElement("cell")> _
        Public ReadOnly Property Cells As List(Of MyDataCell)
            Get
                Return m_cCells
            End Get
        End Property
    
        ' Parameterless constructor to support serialization
        Public Sub New()
            m_cCells = New List(Of MyDataCell)
        End Sub
    
        Public Sub AddCell(sCellName As String, sCellValue As String)
            m_cCells.Add(New MyDataCell(sCellName, sCellValue))
        End Sub
    End Class
    
    Public Class MyDataCell
        <XmlIgnore()> _
        Public Property Name As String
        <XmlText()> _
        Public Property Value As String
    
        ' Parameterless constructor to support serialization
        Public Sub New()
    
        End Sub
        Public Sub New(sCellName As String, sCellValue As String)
            Me.New()
            Me.Name = sCellName
            Me.Value = sCellValue
        End Sub
    End Class
    

    【讨论】:

    • 是的,现在我不知道如何调整您在我上一个问题中发布的内容来修复它:D
    • 甜蜜!我不得不将 total 更改为类似于 page 的属性,因为它没有显示在 XML 中,但它现在可以工作了。我还有一些问题要解决,但我实际上正在获取数据!再次感谢!
    • 我还必须为 request_id 添加设置/结束集,因为它没有创建单元格,只有行 ID。感谢您留下一些空白,让我觉得我不是完全没用:)
    【解决方案2】:

    大家看看这个 flexiuigrid 的演示

    http://flexidemo.ranjitjena.com/

    【讨论】:

      猜你喜欢
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      相关资源
      最近更新 更多