Default sorting of jqgrid on particular field when grid loads

前端 未结 1 1879
感动是毒
感动是毒 2020-12-20 05:56

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

相关标签:
1条回答
  • 2020-12-20 06:12

    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);
        }
    }
    

    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.

    0 讨论(0)
提交回复
热议问题