开发者

how can i call refresh method

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 ques开发者_JAVA百科tion

thank you for you answer


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜