单击列标题会按升序显示jqgrid

时间:2013-02-06 09:35:41

标签: java jquery html jqgrid mvcgrid

目前我在java jqgrid工作我想在点击列标题后显示已排序的网格。我已经使用onsortcol.but它不工作.her是我的code.onsort col函数处于活动状态但它不执行sort.thanks提前

CODE:

    jq(function() {
        var base = "<%=request.getContextPath()%>";
        var  records = -1;
        jq("#grid").jqGrid({
        url:base+'/admin/adminusermanagecrud.htm',
        datatype: 'json',
        mtype: 'GET',
        colNames:['', 'Name','Employee ID','User Name','Mobile','City','State','Is Active','Created Date','Role','Bank Name'],
        colModel:[
            {name:'id',index:'id',  width:55,editable:false,hidden:true},
            {name:'adminName',index:'adminName', width:175,editable:true,sortable:true, editrules:{edithidden:true,required:false}, editoptions:{size:25,readonly:false,disabled:false},search:false},
            {name:'adminEmployeeId',index:'adminEmployeeId', width:175,editable:true, editrules:{edithidden:true,required:false}, editoptions:{size:25,readonly:true,disabled:false},search:true},
            {name:'adminuserName',index:'adminuserName', width:175,editable:true, editrules:{edithidden:false,required:false}, editoptions:{size:25,readonly:false,disabled:false},search:true},
            {name:'mobile',index:'mobile', width:175,editable:true, editrules:{edithidden:false,required:false}, editoptions:{size:25,disabled:false},search:true},
            {name:'city',index:'city', width:175,editable:true, editrules:{edithidden:true,required:false}, editoptions:{size:25,disabled:true},search:true},
            {name:'state',index:'state', width:175,editable:true, editrules:{edithidden:true,required:false}, editoptions:{size:25,disabled:true},search:true},
            {width:165,formatter:linkFormat,editable:true,edittype:'select',editrules:{edithidden:true,required:false}, editoptions:{value:"0:Activate;1:De-Activate",size:25,disabled:false,multiple:false},search:false},
            {name:'createDate',index:'createDate',width:185,editable:true, editrules:{edithidden:true,required:false}, editoptions:{size:25,disabled:true},search:false},
            {name:'role',index:'role',width:175,editable:true,editrules:{edithidden:true,required:false},editoptions:{size:25,disabled:true},search:false},
            {name:'bankName',index:'bankName',width:175,editable:true,editrules:{edithidden:true,required:false},editoptions:{size:25,disabled:true},search:false}

        ],

        postData:{ 
        },
        loadError:function(xhr,status,error)
        {
            var base = "<%=request.getContextPath()%>";
            alert(status);
            if(xhr.status == '403' || xhr.status == '401' || status == 'parsererror')
                {
                    window.location.href = base+"/login.htm";
                }
        },
        rowNum:5,
        //rowList:[5,10,15,20],
        height: 150,
        //width:750,
        autowidth: true,
        rownumbers: true,
        pager: '#pager',
        sortname: 'adminName',
        scrollrows:true,
        viewrecords: true,
        sortorder: "asc",
        caption:"Admin Users Summary",
        onSortCol: function (index, columnIndex, sortOrder) {
            alert(index);
            return 'stop';
        },
        cellEdit: false,
        emptyrecords: "Search returned no results",
        loadonce: false,
        loadComplete: function()
        {
        },
        jsonReader : {
            root: function(obj)
            {
                if(obj.status == false)
                {
                    window.location.href = base+"/login.htm";
                }
                else
                {
                    records = obj.records;
                    return obj.rows;
                }
            },
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            cell: "cell",
            id: "id"
        },
        editurl:base+"/admin/edit.htm"
    });

    jq("#grid").navGrid('#pager',
            {edit:false,add:false,del:false,search:true,excel:true},

            { },
            { },
            { }, 
            { 
                sopt:['eq','cn', 'bw', 'ew'],
                closeOnEscape: true, 
                multipleSearch: false, 
                closeAfterSearch: true
             }
    );

    jq("#btnFilter").click(function()
    {
    jq("#grid").jqGrid('searchGrid',
        {
        multipleSearch: false, 
        sopt:['eq']
        }
        );
    });

});

1 个答案:

答案 0 :(得分:0)

在控制器内部,您需要处理排序。类似于

的东西
var pagedQuery = filteredQuery.OrderBy(sidx + " " + sord).Skip((page - 1) * rows).Take(rows);

您实际对数据集进行排序并将其返回到jqGrid。