排序不在jqgrid中工作 [英] sorting not working in jqgrid

查看:61
本文介绍了排序不在jqgrid中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





单击列标题时不会进行排序。 正在加载...会短暂显示数据,但列未进行排序。此外,OnSortCol事件被触发,我可以看到警报弹出。但是,排序没有发生。对此有任何帮助表示赞赏。



请在下面找到代码:



Hi,

Sorting is not happening on the click of column headers. The "Loading..." shows up briefly over the data, but the columns are not getting sorted. Also, "OnSortCol" event gets triggered and I could see the alert popping up. But, the sorting is not happening. Any help on this is appreciated.

Please find below the code:

jQuery("#jqTable").jqGrid({
            dataType: 'local',
            altRows: true,
            colNames: ["ID", "First name", "Last name", "Role", "Group", "Location", "Status", "<div class='selectgriddiv'>Select all</div>" + "<div class='selectgriddiv'><input type='checkbox' id='chkAll' name = 'chkSelectAll' onclick='checkBox(event)' /></div>", "Role Id", "Is Primary"],
            colModel: [
                {
                    name: "Id", index: "Id", align: "center", sortable: false, formatter: function (cellvalue, options, rowObject) {
                        if (_RoleId > rowObject.RoleId && rowObject.IsPrimary == false)
                            return "<img src='../images/ProcessImages.aspx.jpg' alt='my image' />" + "<br/>" + "<a id='linkToProfile' href='#' onclick='RedirectUsers(" + rowObject.Id + "," + rowObject.RoleId + "," + '"' + rowObject.RoleName + '"' + ")' >" + rowObject.Id + "</a>";
                        else if (_RoleId == rowObject.RoleId || _RoleId < rowObject.RoleId) {
                            return "<img src='../images/ProcessImages.aspx.jpg' alt='my image' />" + "<br/>" + rowObject.Id;
                        }
                        else if (_RoleId == rowObject.RoleId && _IsPrimary == false) {
                            return "<img src='../images/ProcessImages.aspx.jpg' alt='my image' />" + "<br/>" + rowObject.Id;
                        }
                    }
                },
                {
                    name: "FirstName", index: "FirstName", sortable: true, align: "left"
                },
                { name: "LastName", index: "LastName", sortable: true, align: "left" },
                {
                    name: "RoleName", index: "RoleName", sortable: true, align: "left", formatter: function (cellvalue, options, rowObject) {
                        return rowObject.RoleName
                    }
                },
                {
                    name: "MyGroups", index: "MyGroups", sortable: true, align: "left", formatter: function (cellvalue, options, rowObject) {
                        if (rowObject.MyGroups != null)
                            return rowObject.MyGroups
                        else
                            return ""
                    }
                },
                {
                    name: "LocationName", index: "LocationName", sortable: false, align: "left", formatter: function (cellvalue, options, rowObject) {

                        if (rowObject.RegionName != null && rowObject.LOName != null && rowObject.CentreName != null) {
                            return rowObject.RegionName + '.<br/>' + rowObject.LOName + '.<br/>' + rowObject.CentreName
                        }
                        else if (rowObject.RegionName == null && rowObject.LOName != null && rowObject.CentreName != null) {
                            return rowObject.LOName + '.<br/>' + rowObject.CentreName
                        }
                        else if (rowObject.RegionName != null && rowObject.LOName == null && rowObject.CentreName != null) {
                            return rowObject.RegionName + '.<br/>' + rowObject.CentreName
                        }
                        else if (rowObject.RegionName != null && rowObject.LOName != null && rowObject.CentreName == null) {
                            return rowObject.RegionName + '.<br/>' + rowObject.LOName
                        }
                        else if (rowObject.RegionName != null && rowObject.LOName == null && rowObject.CentreName == null) {
                            return rowObject.RegionName
                        }
                        else if (rowObject.RegionName == null && rowObject.LOName != null && rowObject.CentreName == null) {
                            return rowObject.LOName
                        }
                        else if (rowObject.RegionName == null && rowObject.LOName == null && rowObject.CentreName != null) {
                            return rowObject.CentreName
                        }
                        else if (rowObject.RegionName == null && rowObject.LOName == null && rowObject.CentreName == null) {
                            return rowObject.LocationName
                        }
                    }
                },
                {
                    name: "StatusDetail", index: "StatusDetail", sortable: false, align: "left", formatter: function (cellvalue, options, rowObject) {
                        return rowObject.StatusDetail
                    }
                },
                {
                    name: "Select", index: "Select", sortable: false, align: "center", resizable: false, sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return "<input type='checkbox' id='chkFields' " + rowObject.Id + " class='fieldChk' onclick='fieldCheckBox(event)'/>";
                    }
                },
                {
                    name: "RoleId", index: "RoleId", hidden: true, formatter: function (cellvalue, options, rowObject) {
                        return rowObject.RoleId
                    }
                },
                {
                    name: "IsPrimary", index: "IsPrimary", hidden: true, formatter: function (cellvalue, options, rowObject) {
                        return rowObject.IsPrimary
                    }
                }
            ],
            sortorder: "desc",
            viewrecords: true,
            width: 728,
            height: 'auto',
            onSortCol: function (name, index) {
                alert(name);
            }
            
        });





谢谢,

B.R.S.K. Bharadwaj



Thanks,
B.R.S.K. Bharadwaj

推荐答案

Hello Ganesh,



对于jQGrid,如果除local以外的数据类型,则排序需要在服务器端处理。对于客户端排序,数据类型必须是本地,并且每个可排序列必须设置sorttype属性(请参阅 [ ^ ]链接了解详情服务器端分页和客户端分类设置)。此属性的可能值为



  • int / integer - 用于排序整数
  • float / number / currency - for排序十进制数
  • 日期 - 用于排序日期
  • text - 用于文本排序
  • function - 定义用于排序的自定义函数。对于这个函数,我们传递要排序的值,它也应该返回一个值。
Hello Ganesh,

For jQGrid if datatype other than "local" the sorting needs to get handled on the server side. For client side sorting the datatype must be "local" and each sortable column must have the sorttype property set (see this[^] link to know more about server side paging and client side sorting setup). The possible values for this property are

  • int/integer - for sorting integer
  • float/number/currency - for sorting decimal numbers
  • date - for sorting date
  • text - for text sorting
  • function - defines a custom function for sorting. To this function we pass the value to be sorted and it should return a value too.


以下解决方案适合我。只需包含loadComplete fucntion调用

http://stackoverflow.com/questions/16378544/jquery-jqgrid-not-sorting-on-client-side
below solution worked for me. just include the loadComplete fucntion call
http://stackoverflow.com/questions/16378544/jquery-jqgrid-not-sorting-on-client-side


这篇关于排序不在jqgrid中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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