重新加载不适用于jqgrid [英] reload not working for jqgrid

查看:105
本文介绍了重新加载不适用于jqgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码不会重新加载网格.

The following code does not reload the grid.

$("#myjqgrid").trigger('reloadGrid');

如果我理解正确,即使没有数据更改,它也应该进行ajax调用并重新加载网格.

If I understand it correctly, it should make an ajax call and reload the grid even if there are no changes to the data.

HTML

<table id="myjqgrid"></table>
<div id="Pager"></div>

JSON

{
    "colModel": [
        {
            "name": "ID",
            "label": "ID",
            "width": 60,
            "align": "left",
            "jsonmap": "cells.0.value",
            "sortable": true      
        },
        {
            "name": "FirstName",
            "label": "FirstName",
            "width": 100,
            "align": "left",
            "jsonmap": "cells.1.value",
            "sortable": false       
        },
        {
            "name": "LastName",
            "label": "LastName",
            "width": 100,
            "align": "left",
            "jsonmap": "cells.2.value",
            "sortable": false       
        }
    ],
    "colNames": [
        "ID",
        "FirstName",
        "LastName"
    ],
    "mypage": {
        "outerwrapper": {
            "page":"1",
            "total":"1",
            "records":"20",
            "innerwrapper": {
                "rows":[
                    {
                        "id":"1",
                        "cells":
                        [               
                            {
                                "value":"12345",
                                "label": "ID"                       
                            },
                            {
                                "value":"David",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Smith",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"2",
                        "cells":
                        [               
                            {
                                "value":"37546",
                                "label": "ID"                       
                            },
                            {
                                "value":"Willy",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Peacock",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"3",
                        "cells":
                        [               
                            {
                                "value":"62345",
                                "label": "ID"                       
                            },
                            {
                                "value":"Kim",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Holmes",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"4",
                        "cells":
                        [               
                            {
                                "value":"186034",
                                "label": "ID"                       
                            },
                            {
                                "value":"Andy",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Wills",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"5",
                        "cells":
                        [               
                            {
                                "value":"67345",
                                "label": "ID"                       
                            },
                            {
                                "value":"Paul",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Lawrence",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"6",
                        "cells":
                        [               
                            {
                                "value":"12906",
                                "label": "ID"                       
                            },
                            {
                                "value":"Andy",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Charlery",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"7",
                        "cells":
                        [               
                            {
                                "value":"564565",
                                "label": "ID"                       
                            },
                            {
                                "value":"Bets",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Josilyn",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"8",
                        "cells":
                        [               
                            {
                                "value":"34345",
                                "label": "ID"                       
                            },
                            {
                                "value":"Pink",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Floyd",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"9",
                        "cells":
                        [               
                            {
                                "value":"3429",
                                "label": "ID"                       
                            },
                            {
                                "value":"Rose",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Ben",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"10",
                        "cells":
                        [               
                            {
                                "value":"6668",
                                "label": "ID"                       
                            },
                            {
                                "value":"Amy",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Wills",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"11",
                        "cells":
                        [               
                            {
                                "value":"22786",
                                "label": "ID"                       
                            },
                            {
                                "value":"Zarine",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Khan",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"12",
                        "cells":
                        [               
                            {
                                "value":"56444",
                                "label": "ID"                       
                            },
                            {
                                "value":"Dolly",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Mathews",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"13",
                        "cells":
                        [               
                            {
                                "value":"99453",
                                "label": "ID"                       
                            },
                            {
                                "value":"Ginger",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Wills",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"14",
                        "cells":
                        [               
                            {
                                "value":"1234",
                                "label": "ID"                       
                            },
                            {
                                "value":"Fabrice",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Papa",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"15",
                        "cells":
                        [               
                            {
                                "value":"45000",
                                "label": "ID"                       
                            },
                            {
                                "value":"Helen",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Kites",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"16",
                        "cells":
                        [               
                            {
                                "value":"1255",
                                "label": "ID"                       
                            },
                            {
                                "value":"Barbara",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Dorris",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"17",
                        "cells":
                        [               
                            {
                                "value":"5555",
                                "label": "ID"                       
                            },
                            {
                                "value":"Eugene",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Mark",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"18",
                        "cells":
                        [               
                            {
                                "value":"1867",
                                "label": "ID"                       
                            },
                            {
                                "value":"Harry",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"King",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"19",
                        "cells":
                        [               
                            {
                                "value":"45888",
                                "label": "ID"                       
                            },
                            {
                                "value":"Lorraine",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Williams",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"20",
                        "cells":
                        [               
                            {
                                "value":"4567777",
                                "label": "ID"                       
                            },
                            {
                                "value":"Mark",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Sheppard",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    },
                    {
                        "id":"21",
                        "cells":
                        [               
                            {
                                "value":"7777",
                                "label": "ID"                       
                            },
                            {
                                "value":"Davis",
                                "label": "FirstName"    
                            },
                            {                           
                                "value":"Sheppard",
                                "label": "LastName"                         
                            }                                                                                       
                        ]       
                    }
                ]
            }
        }
    }
}

JQGrid定义

$(document).ready(function () { 
    $.ajax({
        type: "GET",
        url: "myjqgrid.json",
        data: "",
        dataType: "json",
        success: function(response){
            var columnData = response.mypage.outerwrapper,
                columnNames = response.colNames,
                columnModel = response.colModel;

            $("#myjqgrid").jqGrid({
                datatype: 'jsonstring',
                datastr: columnData,                
                colNames: columnNames,
                colModel: columnModel,
                jsonReader: {
                    root: "innerwrapper.rows",              
                    repeatitems: false
                },
                gridview: true,
                pager: "#Pager",
                rowNum: 21,
                rowList: [21],
                viewrecords: true,              
                recordpos: 'left',
                multiboxonly: true,
                multiselect: true,
                sortname: 'ID',
                sortorder: "desc",  
                sorttype: "text",   
                sortable: true,
                caption: "<h2>MY JQGRID</h2>",
                width: "1406",      
                height: "100%",
                scrolloffset: 0,    
                loadonce: true,     
                cache: true,
                loadComplete: function(data){

                }
            });
            $("#myjqgrid").jqGrid('navGrid','#Pager', {add:false, edit:false, del:false, position: 'right'});
            $("#myjqgrid").jqGrid('gridResize',{minWidth:800,maxWidth:1405,minHeight:350,maxHeight:680});
            $("#myjqgrid").trigger('reloadGrid');
        }
    });
});

推荐答案

在我看来,您对loadonce: true只是有问题,它会在第一次加载数据后将datatype更改为本地".因此,数据的分页,排序和过滤在本地有效.

It seems to me that you have just problem with loadonce: true which change the datatype to 'local' after the first load of data. So the paging, sorting and filtering of data works locally.

如果您确切地了解什么是分页,排序和过滤,您会发现它的变化更多是因为更改了jqGrid的某些参数并在本地 重新加载了网格.因此,分页,排序和筛选仅在本地工作,因为网格的重新加载在本地工作.

If you look exactly what is paging, sorting and filtering you will see that it's mot more as changing of some parameters of jqGrid and reloading of the grid locally. So the paging, sorting and filtering work locally only because the reload of the grid works locally.

如果您需要从服务器刷新网格的数据,只需将datatype重置为其初始值('json'或'xml'),然后重新加载网格.

If you need to refresh the data of the grid from the server you need just reset the datatype to it's initial value ('json' or 'xml') and then reload the grid.

请参见此处此处以获取代码示例.

See here and here for code examples.

这篇关于重新加载不适用于jqgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆