我有一个带有multiplesearch的jqgrid。如果搜索没有结果,则loadComplete函数没有执行,并且网格中的数据没有重新加载。 这是我的代码:
$("#lusuarios").jqGrid({
url:'usuarios/userList.asp',
datatype: "xml",
mtype: 'GET',
colNames:['Nombre','Login', 'Clave', 'Perfil'],
colModel:[ {name:'Us_Nombre',index:'Us_Nombre', width:75,editable:true,editoptions:{readonly:false,size:20},editrules:{required:true}},
{name:'Us_Login',index:'Us_Login', width:90,editable:true,editoptions:{readonly:false,size:20},editrules:{required:true}},
{name:'Us_Clave',index:'Us_Clave', width:90,editable:true,editoptions:{readonly:false,size:20},editrules:{required:true}},
{name:'Us_Perfil_Id',index:'Us_Perfil_Id', width:100,stype:'select',search:true,searchoptions: {sopt: ['eq'],dataUrl: 'usuarios/perfilesList.asp'},editable:true,edittype:"select",editoptions:{ dataUrl : 'usuarios/perfilesList.asp'},editrules:{required:true}} ],
rowNum:10,
autowidth: true,
pager: '#pusuarios',
sortname: 'Us_Nombre',
viewrecords: true,
sortorder: "desc",
caption:"Usuarios",
multiselect:false,
height: "100%",
emptyrecords: 'No hay usuarios que cumplan los criterios.',
loadComplete: cargaCompletaUsuarios,
editurl: "usuarios/userUpdate.asp",
scrollOffset:0
});
$("#lusuarios").navGrid('#pusuarios',
{edit:true,add:true,del:true,search:true}, //options
{},//height:300,width:600,reloadAfterSubmit:true}, // edit options
{},//height:300,width:600,reloadAfterSubmit:true}, // add options
{},//reloadAfterSubmit:true}, // del options
{closeOnEscape: true, multipleSearch: true, closeAfterSearch: true} // search options
);
function cargaCompletaUsuarios()
{
alert( $('#lusuarios').jqGrid('getGridParam', 'reccount'));
}//function cargaCompletaUsuarios() {
这是搜索后的xml:
<?xml version='1.0' encoding='utf-8'?><rows><page>0</page><total>0</total><records>0</records></rows>
这是服务器端的代码:
<%@Language="VBSCRIPT" CODEPAGE="65001"%>
<%Option Explicit%>
<%Response.Buffer=TRUE%>
<script language="JScript" runat="server" src='/xxxxxxxxxxx'></script>
<!-- #include virtual="xxxxxxxxxxxxxxx" -->
<%
Function Ceiling(intNumber)
Dim dblNumber
dblNumber = CDbl(intNumber)
If Int(dblNumber * 10) MOD 10 > 0 Then
Ceiling = Int(dblNumber) + 1
Else
Ceiling = Int(dblNumber)
End If
End Function
%>
<%
Dim strPage, strLimit, strIdx, strOrd, strCount, strTotalPages, strStart
Dim strSQL, dblCounter
Dim strSearchOn, strField, strFieldData, strSearchOper, strWhere
strPage = CInt(Request("page"))
strLimit = CInt(Request("rows"))
strIdx = Request("sidx")
strOrd = Request("sord")
strSearchOn = Request("_search")
If (strSearchOn = "true") Then
strField = Request("searchField")
If strField="" Then
Dim filtros, tamanio, i, strCampo, strOperador, strDato, strOpGrupo
filtros = Request("filters")
Set filtros = JSON.parse(filtros)
strOpGrupo = filtros.groupOp
tamanio=filtros.rules.length
For i = 0 To tamanio-1
strCampo = filtros.rules.get(i).field
strOperador = filtros.rules.get(i).op
strDato = filtros.rules.get(i).data
If strWhere = "" Then
strWhere = " Where " & strCampo
Else
strWhere = strWhere & " " & strOpGrupo & " " & strCampo
End If
Select Case strOperador
Case "bw" : 'Begin With
strDato = strDato & "%"
strWhere = strWhere & " LIKE '" & strDato & "'"
Case "eq" : 'Equal
If(IsNumeric(strDato)) Then
strWhere = strWhere & " = " & strDato
Else
strWhere = strWhere & " = '" & strDato & "'"
End If
Case "ne": 'Not Equal
If(IsNumeric(strDato)) Then
strWhere = strWhere & " <> " & strDato
Else
strWhere = strWhere & " <> '"& strDato &"'"
End If
Case "lt": 'Less Than
If(IsNumeric(strDato)) Then
strWhere = strWhere & " < " & strDato
Else
strWhere = strWhere & " < '"& strDato &"'"
End If
Case "le": 'Less Or Equal
If(IsNumeric(strDato)) Then
strWhere = strWhere & " <= " & strDato
Else
strWhere = strWhere & " <= '"& strDato &"'"
End If
Case "gt": 'Greater Than
If(IsNumeric(strDato)) Then
strWhere = strWhere & " > " & strDato
Else
strWhere = strWhere & " > '"& strDato &"'"
End If
Case "ge": 'Greater Or Equal
If(IsNumeric(strDato)) Then
strWhere = strWhere & " >= " & strDato
Else
strWhere = strWhere & " >= '"& strDato &"'"
End If
Case "ew" : 'End With
strWhere = strWhere & " LIKE '%" & strDato & "'"
Case "cn" : 'Contains
strWhere = strWhere & " LIKE '%" & strDato & "%'"
End Select
Next
Else
If (strField = "Us_Nombre" Or strField = "Us_Login" Or strField = "Us_Perfil_Id") Then
strFieldData = Request("searchString")
strSearchOper = Request("searchOper")
'construct where
strWhere = " Where " & strField
Select Case strSearchOper
Case "bw" : 'Begin With
strFieldData = strFieldData & "%"
strWhere = strWhere & " LIKE '" & strFieldData & "'"
Case "eq" : 'Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & " = " & strFieldData
Else
strWhere = strWhere & " = '" & strFieldData & "'"
End If
Case "ne": 'Not Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & " <> " & strFieldData
Else
strWhere = strWhere & " <> '"& strFieldData &"'"
End If
Case "lt": 'Less Than
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & " < " & strFieldData
Else
strWhere = strWhere & " < '"& strFieldData &"'"
End If
Case "le": 'Less Or Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & " <= " & strFieldData
Else
strWhere = strWhere & " <= '"& strFieldData &"'"
End If
Case "gt": 'Greater Than
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & " > " & strFieldData
Else
strWhere = strWhere & " > '"& strFieldData &"'"
End If
Case "ge": 'Greater Or Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & " >= " & strFieldData
Else
strWhere = strWhere & " >= '"& strFieldData &"'"
End If
Case "ew" : 'End With
strWhere = strWhere & " LIKE '%" & strFieldData & "'"
Case "cn" : 'Contains
strWhere = strWhere & " LIKE '%" & strFieldData & "%'"
End Select
End if
End If
End If
Call OpenDB()
strSQL = "Select Count(*) As count From XXXXXX LEFT JOIN XXXXXX ON XXXXX = XXXXXX "&strWhere&" "
'response.write strSQL
Set rs = dbConn.Execute(strSQL)
strCount = CInt(rs("count"))
If (strCount > 0) Then
strTotalPages = strCount / strLimit
Else
strTotalPages = 0
End If
strTotalPages = Ceiling(strTotalPages)
If (strPage > strTotalPages) Then
strPage = strTotalPages
End If
strStart = strLimit * strPage - strLimit
If (strStart < 0) Then
strStart = 0
End If
strSQL = "SELECT Us_Codigo_Id, Us_Nombre, Us_Login, Us_Clave, Pf_Descripcion From XXXXXXXX LEFT JOIN XXXXXXXX ON XXXXXXXXXXX = XXXXXXXXX "&strWhere&" "
strSQL = strSQL & "ORDER BY "&strIdx&" "&strOrd
Set rs = dbConn.Execute(strSQL)
'response.Write strSQL
Response.Write ("<?xml version='1.0' encoding='utf-8'?>")
Response.Write "<rows>"
Response.Write "<page>"&strPage&"</page>"
Response.Write "<total>"&strTotalPages&"</total>"
Response.Write "<records>"&strCount&"</records>"
dblCounter = 1
Do While Not rs.Eof
Response.contenttype = "text/xml;charset=utf-8?"
Response.Write "<row id='" & rs("Us_Codigo_Id") & "'>"
Response.Write "<cell>" & rs("Us_Nombre") & "</cell>"
Response.Write "<cell>" & rs("Us_Login") &"</cell>"
Response.Write "<cell>" & rs("Us_Clave") &"</cell>"
response.Write "<cell>" & rs("Pf_Descripcion") & "</cell>"
Response.Write "</row>"
dblCounter = dblCounter + 1
rs.MoveNext
Loop
Response.Write "</rows>"
Call CloseDB()
%>
抱歉我的英文。