我怎样才能调用刷新方法
问题是这样的 我初始化了一个没有 postData 的 jqgrid , 并设置 hiddengrid:true,
我想在没有请求的情况下首先初始化表, 然后会手动请求数据,
js
var showRoleList = function($entityList,pagerId)
{
$entityList.jqGrid({
url:'servlet/RoleAction',
datatype: 'json',
height: 'auto',
jsonReader:
{
repeatitems : false,
userdata: "rows"
},
colNames:['ID','roleName','detail','action'],
colModel:
[
{name:'id',index:'id',hidden:true},
{name:'name',index:'name', width:100,sortable:false},
{name:'description',index:'description', width:400,sortable:false},
{name:'action',index:'action', width:40,sortable:false}
],
rowNum:10,
altRows:true,
autowidth:true,
mtype: "POST",
rownumbers: true,
rownumWidth: 30,
imgpath:'css/images',
sortorder:'desc',
viewrecords: true,
multiselect:true,
loadui:'disable' ,
gridview:true,
hiddengrid:true,
page:1,
pginput:true,
pager: pagerId,
sortname: 'dateEntered',
altclass:'ui-priority-secondary_1',
});
}
showRoleList($("#entityList0"),"#pEntityList0");
**$entityList0.jqGrid("setGridParam", {
postData:{ACTION:'userRelation',userId:user.id,typeName:'role',flag:true},
});**
**$entityList0.trigger("reloadGrid", [{page:1}]);**
html:
<table id="entityList0"></table>
<div id="pEntityList0"></div>
但是失败 当我调用触发器时,可以发送请求,但是如果没有 postData,
则没有参数可以发布到服务器,
但是如果我单击刷新按钮,它可以工作,
我该如何解决这个问题,
谢谢您的回答
the question is like this
i init a jqgrid without postData ,
and set hiddengrid:true,
i want to init table at first with no request,
then will request data by hand,
js
var showRoleList = function($entityList,pagerId)
{
$entityList.jqGrid({
url:'servlet/RoleAction',
datatype: 'json',
height: 'auto',
jsonReader:
{
repeatitems : false,
userdata: "rows"
},
colNames:['ID','roleName','detail','action'],
colModel:
[
{name:'id',index:'id',hidden:true},
{name:'name',index:'name', width:100,sortable:false},
{name:'description',index:'description', width:400,sortable:false},
{name:'action',index:'action', width:40,sortable:false}
],
rowNum:10,
altRows:true,
autowidth:true,
mtype: "POST",
rownumbers: true,
rownumWidth: 30,
imgpath:'css/images',
sortorder:'desc',
viewrecords: true,
multiselect:true,
loadui:'disable' ,
gridview:true,
hiddengrid:true,
page:1,
pginput:true,
pager: pagerId,
sortname: 'dateEntered',
altclass:'ui-priority-secondary_1',
});
}
showRoleList($("#entityList0"),"#pEntityList0");
**$entityList0.jqGrid("setGridParam", {
postData:{ACTION:'userRelation',userId:user.id,typeName:'role',flag:true},
});**
**$entityList0.trigger("reloadGrid", [{page:1}]);**
html:
<table id="entityList0"></table>
<div id="pEntityList0"></div>
but failed
when i called trigger, request can be sent,but without postData
no param can post to server
but if i click refresh button it can work
how can i resolve this question
thank you for you answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现你的问题。唯一明显的语法错误是
flag:true},})
必须替换为flag:true}})
(删除逗号)。以同样的方式,您应该将altclass:'ui-priority-secondary_1',}
替换为altclass:'ui-priority-secondary_1'}
。所有代码都在
$(document).ready(function() {/*here*/});
中吗?在代码中,变量
user
和$entityList0
未初始化。您确定使用 set$entityList0=$("#entityList0")
并将user
至少初始化为上面代码中的{}
?例如,您还应该删除已弃用的
imgpath
参数,并将sortname: 'dateEntered'
替换为sortname: 'name'
。如果您发布您使用的任何测试数据,我可以为您提供您发布的代码的网址,该代码对我来说没有任何问题。
更新:好的!现在有了可以测试的代码,我知道你的问题出在哪里。问题是您尝试在第一个 ajax 请求结束之前启动第二个 ajax 请求。
您的网格具有
数据类型:'json'
。在showRoleList($entityList0,'#pEntityList0');
行中,您启动第一个 ajax 请求,然后立即启动第二个请求$entityList0.trigger("reloadGrid")< /代码>。第一个请求将内部变量
$("#entityList0")[0].grid.hDiv.loading
设置为 true,您启动的所有其他请求将被忽略,直到超时或响应或错误从服务器返回。在设置
postData
参数之前,您可能并不真正想发送第一个请求。因此,您应该在 jqGrid 初始化时(在showRoleList
函数中)使用datatype: 'local'
。然后,您应该在postData
之外设置datatype: 'json'
:或者,您需要在重新加载网格之前中止先前的 ajax 调用。如果确实需要,我可以解释如何实现这一点。
I can't reproduce your problem. The only clear syntax error is
flag:true},})
muss be replaced toflag:true}})
(remove comma). In the same way you should replacealtclass:'ui-priority-secondary_1',}
toaltclass:'ui-priority-secondary_1'}
.Is all the code inside of
$(document).ready(function() {/*here*/});
?In the code variables
user
and$entityList0
are not initialized. Are you sure, that use set$entityList0=$("#entityList0")
and initializeuser
at least as{}
in the code above?You should also remove deprecated
imgpath
parameter and replacesortname: 'dateEntered'
tosortname: 'name'
for example.If you post any test data which you use I could give you url to the code which you posted and which work at me without any problem.
UPDATED: OK! Now having the code which one can test I see where your problem is. The problem is that you try to start the second ajax request before the first one is ended.
Your grid has
datatype: 'json'
. In the lineshowRoleList($entityList0,'#pEntityList0');
you start the first ajax request and then immediately start the second one with respect of$entityList0.trigger("reloadGrid")
. The first request set internal variable$("#entityList0")[0].grid.hDiv.loading
to true and all other requests which you start will be just ignored till the timeout or the response or error returned from the server.Probably you not really want to send the first request till you set the
postData
parameters. So you should usedatatype: 'local'
at the initialization time of jqGrid (in theshowRoleList
function). Then you should setdatatype: 'json'
additionally to thepostData
:Alternative you will need to abort the previous ajax call before reloading of the grid. If it is really needed I could explain how you can implement this.
创建一个 test.html
好的,我只是在第一次打开 url test.html 时
,然后单击刷新按钮,
您可以测试它,
您可以看到结果不同
这是一个简单的页面,您可以轻松测试!如果您发现有问题请告诉我谢谢
ok i just make a test.html
when the first time open the url test.html
an then i click refresh button
you can test it
you can see the result is different
this is a simple page ,you can test easily ! if you can find something wrong please tell me thank you