jqgrid - 排序图标未在设置排序顺序时更新

标签 jqgrid jqgrid-formatter

我正在尝试使用以下代码更改 jqGrid 的排序顺序:

jQuery('#id').setGridParam({sortorder:"desc"}).trigger("reloadGrid");

它更改了表格的排序顺序,但表格的排序图标未按顺序更改。在 onSortCol 中,我正在对实际对列进行排序的列进行排序。但是当我使用上面的代码设置排序顺序时,排序顺序已经设置但是排序图标仍然显示之前的排序顺序。

_table.jqGrid({

        datatype: 'local', // disable initial autoload. this will be when load function is called "json",
        altRows: true,
        altclass : 'AltRowClass',
        gridView: true,
        width:850,
        height:"auto",
        rowheight: 75,        
        align: 'center',
        treeGrid: false, 
        loadonce:true,
        ExpandColumn: 'name',
        loadtext : 'Currently updating',
        mtype : 'POST',
        colNames: ['MSISDN','IMSI','Last name','First name','Device type','CE Index','Customer lifetime value'],
        colModel: [
                   { name: 'MSISDN', align: 'center', hidden: false, sortable: false,formatter: maskingColumn},
                   { name: 'IMSI', align: 'center', hidden: false, sortable: false,formatter: maskingColumn},
                   { name: 'LastName', align: 'center', hidden: false, sortable: false}, 
                   { name: 'FirstName', align: 'center', hidden: false, sortable: false}, 
                   { name: 'DeviceType', align: 'center', hidden: false, sortable: false,formatter: columnData},
                   { name: 'CEIndex', align: 'center', hidden: false, sortable: true, sorttype: 'int'},
                   { name: 'CustomerLifetimeValue', align: 'center', hidden: false, sortable: false}
                   ],
        sortname: 'CEIndex',
        sortorder: 'desc',
        loadComplete: function(data) 
        {
            var rowCount = _table.jqGrid('getGridParam', 'records');

            if (rowCount > 5) {
                _table.parents("div.ui-jqgrid-bdiv").css({'max-height':'300px'});
                _table.closest(".ui-jqgrid-bdiv").css({'overflow-y':'auto'}).css({'overflow-x':'hidden'});
            }
            if (rowCount != 0) {
                _table.parents().find('.ui-jqgrid-view').first().show();
            }
            if (rowCount <= rowsNum) {
                utils.find('cei-drill-customer-detail-showmore').hide();
            } else {
                utils.find('cei-drill-customer-detail-showmore').show();
            }
            _table.trigger("reloadGrid");
        } ,
        onSortCol: function (data, status, xhr) {
            if (xhr == 'asc') {
                var postData = this.p.postData.jsonRequest.replace('Top','Bottom');
                actionInputObjectExportCustDrilldown.parameters.requestQuery = actionInputObjectExportCustDrilldown.parameters.requestQuery.replace('Top','Bottom');
                var postDataVar = {
                        operation : 'drillDownLevel1',
                        drillLevel1 : "drilldown",
                        jsonRequest : postData
                };
                _this.load(postDataVar);
            } else if (xhr == 'desc') {
                var postData = this.p.postData.jsonRequest.replace('Bottom','Top');
                actionInputObjectExportCustDrilldown.parameters.requestQuery = actionInputObjectExportCustDrilldown.parameters.requestQuery.replace('Bottom','Top');
                var postDataVar = {
                        operation : 'drillDownLevel1',
                        drillLevel1 : "drilldown",
                        jsonRequest : postData
                };
                _this.load(postDataVar);
            }
        },
       beforeProcessing : function(data, status, xhr) {
            jQuery('div#jqgh_' + prefix + '-cei-dd-customer-details-table_CustomerLifetimeValue.ui-jqgrid-sortable').text("Customer Lifetime Value(" + filterValuesHl.currency + ")");
            if (data.queryError != null || !data.rows || data.rows.length == 0) {
                utils.find('cei-drill-customer-detail-ExportShowMore').hide();
                utils.find('div-for-export-customer').hide();
                var noError = utils.find('cei-customerDetails-div').parent().find(".cei-customer-details-dd-no-data");
                if (data.queryError != null) {
                    noError.text("Error in portlet: " + data.queryError);
                } else {
                    noError.html("<strong>No Data Available</strong>");
                }
                noError.show();
                return false;
            } else {
                utils.find('cei-drill-customer-detail-ExportShowMore').show();
                utils.find('div-for-export-customer').show();
                utils.find('cei-drill-customer-detail-showmore').show();
                //Hiding the columns which has no data in all the rows.
                hideColumns(data);
                //Setting CSV Data
                csvData = data;
            }
        },
        beforeRequest : function() {
            _table.parents().find('.ui-jqgrid-view').first().hide();
            utils.find('cei-customerDetails-div').parent().find(".cei-customer-details-dd-no-data").hide();
        },
        loadError : function(xhr, st, err) {
            utils.find('cei-drill-customer-detail-ExportShowMore').hide();
            utils.find('div-for-export-customer').hide();
            var noError = utils.find('cei-customerDetails-div').parent().find(".cei-customer-details-dd-no-data");
            noError.html("<html>Error connecting portlet: " + err + "</strong>");
            noError.show();
        }

    });

最佳答案

您可以尝试以下代码,其中 id 是您的列名。

$('#grid').jqGrid('setGridParam', {sortorder: 'desc'}); $('#grid').jqGrid('sortGrid', 'id');

关于jqgrid - 排序图标未在设置排序顺序时更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14099108/

相关文章:

jquery - jqGrid过滤工具栏初始默认值

javascript - jqGrid - colNames 和 <> colModel 的长度!错误

javascript - jqGrid 导航网格按钮定位

javascript - 如何在 jQgrid 中隐藏列但在添加/编辑面板中显示此列

javascript - 如果没有返回值,则将货币格式的 JQgrid 单元格保留为空白,没有默认值

jquery - 表单中图像格式化程序的问题

jquery - jqgrid 中类似于 Excel 的过滤

javascript - 使用 jqGrid 进行内联编辑时在表格上方显示表单控件

jquery - jqGrid 自定义 edittype(单选按钮列)自定义元素在编辑时不触发 set 事件

javascript - 如何避免在免费 jqgrid 内联编辑中按下保存按钮时日期损坏