FlexiGrid“无项目",响应清楚地显示数据 [英] FlexiGrid "No Items", response clearly shows data

查看:106
本文介绍了FlexiGrid“无项目",响应清楚地显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该表可见,看起来不错,显示了列标题,但是经过一秒钟的处理中,请稍候...",状态变为无项目".检查DOM中的响应,显示从Web服务正确返回了数据,格式如下:

Table is visible, looks fine, column headers show up, but after a split second of "processing, please wait..." the status goes to "No Items". Inspecting the response in the DOM shows the data is being returned properly from the web service, formatted as follows:

<?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:

Here is the flexigrid javascript in question:

$('#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
});

要获得加分,即使分页无效,如何显示页脚?

And for bonus points, how can I show the footer even if paging is diabled?

更新:我检查了flexigrid演示的DOM,这是格式化返回的XML的方式:

UPDATE: I inspected the DOM for the flexigrid demo and here is how their returned XML is formatted:

<?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>

我猜这就是为什么它不起作用?要查看我如何构建响应,请参见以下问题:

I'm guessing that's why it's not working? To see how I'm building the response, please see this question: vb.net return json object with multiple types?

推荐答案

根据各种信息,我发现

According to various information I have found here and a couple of other locations, flexigrid requires the XML to have specific format:

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是上一个问题的结果而生成的,这是将产生所需输出的那些类的更新版本:

Since the MyDataClass was generated as a result of your previous question, here are updated versions of those classes that will produce the desired output:

<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

这篇关于FlexiGrid“无项目",响应清楚地显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆