网格加载时,jqgrid在特定字段上的默认排序 [英] Default sorting of jqgrid on particular field when grid loads

查看:394
本文介绍了网格加载时,jqgrid在特定字段上的默认排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载一个默认排序的网格,它是字段之一.我是通过在网格中添加sortname和sortorder来完成此操作的,但是当网格加载时,排序标志显示在该字段的标题上.但是,当我单击分页上的下一个按钮而不是网格加载时,记录将进行排序.

I want to load a grid with default sorting on it's one of field. I done this by adding sortname and sortorder to my grid,but when grid is loaded sorting sign is shown on a header of that field.But records are sorted when i click on pagination next button not on grid load.

有人知道为什么它不按网格负荷排序吗?

Is anyone know why it is not sorting on grid load?

@UPDATE: 我正在使用我的数据类型作为XML和我的配置.如下:

@UPDATE: hi kees, I am using my datatype as XML and my config. is as follows:

jQuery("#userList").jqGrid({
    url: '<%=request.getContextPath()%>/userJqGrid?q=1&action=fetchData&userCookie=<%= encodedCookie%>',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['<%= userProp.getProperty(userColNames[0])%>',
              '<%= userProp.getProperty(userColNames[1])%>',
              '<%= userProp.getProperty(userColNames[2])%>',
              '<%= userProp.getProperty(userColNames[3])%>',
              '<%= userProp.getProperty(userColNames[4])%>',
              '<%= userProp.getProperty(userColNames[5])%>'
    ],
    colModel:[
        {name:'<%= userColNames[0]%>',index:'<%= userColNames[0]%>',
            width:120,sortable:true,editable:true,editrules:{required:true},formoptions:{rowpos:1, elmprefix:'*'}},
        {name:'<%= userColNames[1]%>',index:'<%= userColNames[1]%>',
            width:130,sortable:true,editable:true},
        {name:'<%= userColNames[2]%>',index:'<%= userColNames[2]%>',
            width:100,sortable:true,editable:true,editrules:{required:true},formoptions:{rowpos:3, elmprefix:'*'}},
        {name:'<%= userColNames[3]%>',index:'<%= userColNames[3]%>',
            width:180,sortable:true,editable:true,editrules:{email:true,required:true},formoptions:{rowpos:4, elmprefix:'*'}},
        {name:'<%= userColNames[4]%>',index:'<%= userColNames[4]%>',
            width:100,sortable:true,editable:true},
        {name:'<%= userColNames[5]%>',index:'<%= userColNames[5]%>',
            width:100,sortable:true,editable:true},
    ],
    pager:'#pager1',
    rowNum:'<%=appProp.getProperty("per_page_records")%>',
    height:'auto',
    viewrecords:true,
    loadonce:true,
    sortable:true,
    width:'100%',
    gridview: true,
    autowidth:true,
    shrinkToFit:false,
    ignoreCase:true,
    editurl:'<%=request.getContextPath()%>/userJqGrid?q=1&action=addData&userCookie=<%=encodedCookie%>',
    caption: 'User Records',
    sortname:'<%=userColNames[14]%>',
    sortorder:'asc',
    onSelectRow: function (id){
        checkAndSetCookie();
    },
    onSortCol : function(){
        checkAndSetCookie();
    },
    onPaging : function(){
        checkAndSetCookie();
    },
    onSearch : function(){
        checkAndSetCookie();
    },
    loadComplete: function(){
        checkAndSetCookie();
    }
});

推荐答案

如果您使用远程datatype(datatype: 'xml'datatype: 'json')服务器负责在以下位置对数据进行排序第一次加载.如果使用loadonce: true,并且只想在客户端上对数据进行排序,则必须在第一次加载后直接重新加载jqGrid.相应的代码可能与以下内容有关

If you use remote datatype (datatype: 'xml' or datatype: 'json') the server is responsible for sorting of the data at the first load. If you use loadonce: true and want to sort the data only on the client side you have to reload jqGrid directly after the first loading. The corresponding code could be about the following

loadComplete: function (data) {
    var $this = $(this),
        datatype = $this.getGridParam('datatype');

    if (datatype === "xml" || datatype === "json") {
        setTimeout(function () {
            $this.trigger("reloadGrid");
        }, 100);
    }
}

更新:免费jqGrid 叉具有选项,可以与loadonce: true选项结合使用.选项forceClientSorting: true强制客户端进行排序和过滤.不需要答案中描述的代码.

UPDATE: Free jqGrid fork has the option forceClientSorting: true, which can be used in combination with loadonce: true option. The option forceClientSorting: true force client side sorting and filtering. It makes the code described in the answer unneeded.

这篇关于网格加载时,jqgrid在特定字段上的默认排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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