我怎样才能调用刷新方法

发布于 2024-10-24 00:39:34 字数 1793 浏览 5 评论 0原文

问题是这样的 我初始化了一个没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喜你已久 2024-10-31 00:39:34

我无法重现你的问题。唯一明显的语法错误是 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'

$entityList0.jqGrid(
    "setGridParam",
    {
        datatype: 'json',
        postData: {
            ACTION:'userRelation',
            userId:'1111',
            typeName:'role',
            flag:true
        }
    }
);

或者,您需要在重新加载网格之前中止先前的 ajax 调用。如果确实需要,我可以解释如何实现这一点。

I can't reproduce your problem. The only clear syntax error is flag:true},}) muss be replaced to flag:true}}) (remove comma). In the same way you should replace altclass:'ui-priority-secondary_1',} to altclass:'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 initialize user at least as {} in the code above?

You should also remove deprecated imgpath parameter and replace sortname: 'dateEntered' to sortname: '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 line showRoleList($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 use datatype: 'local' at the initialization time of jqGrid (in the showRoleList function). Then you should set datatype: 'json' additionally to the postData:

$entityList0.jqGrid(
    "setGridParam",
    {
        datatype: 'json',
        postData: {
            ACTION:'userRelation',
            userId:'1111',
            typeName:'role',
            flag:true
        }
    }
);

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.

锦爱 2024-10-31 00:39:34

创建一个 test.html

 <html ... 
    <script  type="text/javascript"> 
    var $entityList0;  
     $(function(){

       $entityList0 = $("#entityList0");          
       showRoleList($entityList0,'#pEntityList0');         
       $entityList0.jqGrid("navGrid",'#pEntityList0',{});         
       $entityList0.jqGrid("setGridParam",
        {     
             postData:{ACTION:'userRelation',userId:'1111',typeName:'role',flag:true}
        }).showCol("action");   
        $entityList0.trigger("reloadGrid"); 
        });  
var showRoleList = function($entityList,pagerId) {
            $entityList.jqGrid({
                url:'servlet/RoleAction',
                datatype: 'json',       height: 'auto',
                jsonReader:         {
                    repeatitems : false,
                    userdata: "rows"
                },
                colNames:['ID','roleName','detail','actiokn'],
                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',
            }); } </script> 
</head> 
<body>
          <table id="entityList0"></table>
           <div id="pEntityList0"></div>        
</body> 
</html>

好的,我只是在第一次打开 url test.html 时

    HeadersPostPutHTMLXML
    application/x-www-form-urlencoded
    _search false
    nd  1300458295847
    page    1
    rows    10
    sidx    dateEntered
    sord    desc

_search=false&nd=1300458295847&rows=10&page=1&sidx=dateEntered&sord=desc

,然后单击刷新按钮,

HeadersPostPutHTML
application/x-www-form-urlencoded
ACTION  userRelation
_search false
flag    true
nd  1300458310960
page    1
rows    10
sidx    dateEntered
sord    desc
typeName    role
userId  1111

_search=false&nd=1300458310960&rows=10&page=1&sidx=dateEntered&sord=desc&ACTION=userRelation&userId=1111&typeName=role&flag=true

您可以测试它,

您可以看到结果不同
这是一个简单的页面,您可以轻松测试!如果您发现有问题请告诉我谢谢

ok i just make a test.html

 <html ... 
    <script  type="text/javascript"> 
    var $entityList0;  
     $(function(){

       $entityList0 = $("#entityList0");          
       showRoleList($entityList0,'#pEntityList0');         
       $entityList0.jqGrid("navGrid",'#pEntityList0',{});         
       $entityList0.jqGrid("setGridParam",
        {     
             postData:{ACTION:'userRelation',userId:'1111',typeName:'role',flag:true}
        }).showCol("action");   
        $entityList0.trigger("reloadGrid"); 
        });  
var showRoleList = function($entityList,pagerId) {
            $entityList.jqGrid({
                url:'servlet/RoleAction',
                datatype: 'json',       height: 'auto',
                jsonReader:         {
                    repeatitems : false,
                    userdata: "rows"
                },
                colNames:['ID','roleName','detail','actiokn'],
                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',
            }); } </script> 
</head> 
<body>
          <table id="entityList0"></table>
           <div id="pEntityList0"></div>        
</body> 
</html>

when the first time open the url test.html

    HeadersPostPutHTMLXML
    application/x-www-form-urlencoded
    _search false
    nd  1300458295847
    page    1
    rows    10
    sidx    dateEntered
    sord    desc

_search=false&nd=1300458295847&rows=10&page=1&sidx=dateEntered&sord=desc

an then i click refresh button

HeadersPostPutHTML
application/x-www-form-urlencoded
ACTION  userRelation
_search false
flag    true
nd  1300458310960
page    1
rows    10
sidx    dateEntered
sord    desc
typeName    role
userId  1111

_search=false&nd=1300458310960&rows=10&page=1&sidx=dateEntered&sord=desc&ACTION=userRelation&userId=1111&typeName=role&flag=true

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文