jqGrid的loadonce不asp.net工作 [英] jqGrid loadonce doesn't work with asp.net
问题描述
有谁知道如何解决asp.net + ASMX + jqGrid的排序这个讨厌的问题。
因为,为了调用从jqGrid的pagemethods或ASMX Web服务,它需要被砍死这样的:
Does anyone know how to solve this nasty issue with asp.net+asmx+jqGrid sorting. Because, in order to call pagemethods or asmx web services from jqGrid, it needs to be hacked like this:
datatype: function() {
$.ajax({
url: 'Default.aspx/GetPersons',
data: "{}",
type: "POST",
dataFilter: function(data) {
var msg = eval('(' + data + ')');
if (msg.hasOwnProperty('d'))
return msg.d;
else
return msg;
}
而不是这样的:
datatype: "json"
正因为如此,为了做到在客户端上我的分类法loadonce属性设置为true,无法正常工作和jqGrid的要求发生在每一个网格事件服务器。
Because of that, setting loadonce attribute to true in order to do my sortings on the client, doesn't work and jqGrid calls server for every event that occur in grid.
任何想法?
感谢名单
马尔科
Thanx Marko
推荐答案
我最终放弃了JSON(与ASP.NET),只是使用XML。然后,一切都只是工作。
从ASMX确保返回类型的XmlDocument
I eventually gave up on JSON (with ASP.NET) and just used XML. Then everything just works. Make sure the return type from your asmx is XmlDocument
您需要做的一切的一个很好的总结,使其工作(在客户端至少)可以在在的 jqGrid的维基
A good summary of everything you need to do to make it work (on the client side at least) can be found on the the JQGrid wiki
看看他们的样本XML,并确保你的服务返回的缓冲区(最好提琴手),它遵循相同的模式。
Look at their sample XML and make sure what your service returns a buffer (best to validate with Fiddler) that follows the same schema.
更新 - 有些code样品
UPDATE - Some Code samples
下面是客户端脚本来创建网格
Here is the client side script to create the grid
var mygrid = $("#list").jqGrid({
url: '../../webServices/callsGridService.asmx/getCallsGridDataXML?nd=' + new Date().getTime(),
datatype: 'xml',
mtype: 'POST',
contentType: "text/xml",
colNames: ['Call ID', 'Date / Time', 'Duration'],
colModel: [
{ name: 'callId', index: 'callId', align: "right", key: true },
{ name: 'callTime', index: 'callTime', sorttype: 'date' },
{ name: 'duration', index: 'duration', align: "right" }
],
pager: $('#pager'),
rowNum: 10,
rowList: [10, 25, 50, 100],
sortname: 'callTime',
viewrecords: true,
sortorder: "desc",
height: "100%",
multiselect: true,
rownumbers: true,
gridview: true,
autowidth: true,
caption: "Calls"
})
和这里的服务code(VB.NET):
And here is the service code (VB.NET):
Public Function getCallsGridDataXML() As XmlDocument
Dim xmlRet As New XmlDocument
Dim ret As New StringBuilder
m_pageNum = CInt(HttpContext.Current.Request.Form.Item("page"))
If m_pageNum = Nothing OrElse m_pageNum = 0 Then
m_pageNum = 1
End If
m_pageSize = CInt(HttpContext.Current.Request.Form.Item("rows"))
If m_pageSize = Nothing OrElse m_pageSize = 0 Then
m_pageSize = 10
End If
m_sortItem = CStr(HttpContext.Current.Request.Form.Item("sidx"))
m_sortOrder = CStr(HttpContext.Current.Request.Form.Item("sord"))
Dim dt As DataTable
dt = Session(SESSION_CALLS_GRID_DATA)
Dim myView As DataView = dt.DefaultView
If m_sortItem IsNot Nothing AndAlso m_sortOrder IsNot Nothing Then
myView.Sort = m_sortItem & " " & m_sortOrder
End If
ret.Append("<?xml version='1.0' encoding='utf-8'?>")
ret.Append("<rows>")
ret.Append("<page>" & m_pageNum & "</page>")
ret.Append("<total>" & Math.Floor(dt.Rows.Count / m_pageSize) & "</total>")
ret.Append("<records>" & dt.Rows.Count & "</records>")
For i As Integer = (m_pageNum - 1) * m_pageSize To Math.Min(dt.Rows.Count - 1, m_pageNum * m_pageSize - 1)
ret.Append("<row>")
Dim cellCount As Integer = 0
ret.Append("<cell>" & Server.HtmlEncode(myView(i)("callId")) & "</cell>")
ret.Append("<cell>" & Server.HtmlEncode(myView(i)("callTime")) & "</cell>")
ret.Append("<cell>" & Server.HtmlEncode(myView(i)("duration")) & "</cell>")
ret.Append("</row>")
Next
ret.Append("</rows>")
xmlRet.LoadXml(ret.ToString)
Return xmlRet
End Function
您可以看到我正在创建的XML作为一个字符串,然后将其装入XMLDocumennt。我不能说我知道这是最好的办法。您可以直接在文档构建XML DOM。
You can see I'm building the XML as a string and then loading it into the XMLDocumennt. I can't say I know this is the best way. You could build the XML DOM directly on the document.
这篇关于jqGrid的loadonce不asp.net工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!