0

fresh here and fresh in jqgrid .i have some problems about sorting the jqgrid by given column.please give me an example and following is my code .

 function gridList() {
    var $gridList = $("#gridList1");
    $gridList.dataGrid({
        mtype: 'Get',
        url: '@Url.Action("GetMonthEnrollPlanFinishRateData")',
        postData: { },

        height: $(window).height() - 128,
        colModel: [
            {
                label: "主键", name: "Id", hidden: true, key: true
            },
            { label: '真实姓名', name: 'RealName', width: 150, align: 'left' },
            { label: '本月目标', name: 'CurrentMonthPlan', width: 160, align: 'left'},
            { label: '本月招生', name: 'CurrentMonthFinish', width: 160, align: 'left' },
            { label: '完成率Hidden', name: 'FinishRateHidden', width: 150, align: 'left', hidden: true },
            { label: '完成率', name: 'FinishRate', width: 150, align: 'left' },
            { label: '状态', name: 'Status', width: 150, align: 'left' },
        ],
        pager: '#gridPager1',


        viewrecords: true,
        //sortname: "CurrentMonthPlan",
        //sortorder: "asc",
        ////pginput: true,
        ////caption: "",
        //sortable: true,
    });
}
hafy wang
  • 3
  • 3

1 Answers1

0

If you need to sort the grid by FinishRate column, then you should add sortname: "FinishRate" parameter of jqGrid. It will send additional parameter sidx=FinishRate to url: '@Url.Action("GetMonthEnrollPlanFinishRateData")'. By the way, I'm not sure whether you want to use XML or JSON format of data in communication with the server. You should add datatype: "json" if the server ('@Url.Action("GetMonthEnrollPlanFinishRateData")') returns JSON data.

It's important to understand than jqGrid allows you two alternative scenarios: sorting, paging and filtering/searching on the server side or on the client side. If the total number of rows in the grid isn't too large (for example <1000 or <10000), then it's recommended to use client side scenario. You need just add loadonce: true and forceClientSorting: true options to the grid and to return array of all items from the server. jqGrid will automatically sort the data for you. It's important that you can use forceClientSorting: true option only if you use free jqGrid fork.

If you use an old version of jqGrid or not free jqGrid, then you will have to sort the data locally or to use the trick described in the answer.

If you have large number of items in the grid, that you can't use loadonce: true and you will have to sort the data on the server based on the values of sidx and sord parameters (sord describes the sort direction and it has the value "asc" or "desc").

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798