可排序(按字母顺序排列)

时间:2012-12-27 08:27:02

标签: jquery kendo-ui jquery-ui-sortable

我有一个列表,我正在对它进行排序

sortable: {
    mode: "single",
    allowUnsort: false,
    field: "LastName"
},

问题是,当我点击排序按钮时,字段按字母顺序排序,但首先显示带有大写字母的字段,然后显示带小字母的字段(我说的是第一个字母)。

示例:

  • 管理员
  • 医生
  • 编程
  • 科学家
  • 医生
  • 药剂师
  • 兽医

我想做的是:

  • 管理员
  • 医生
  • 医生
  • 药剂师
  • 编程
  • 科学家
  • 兽医

这是我的代码

    var selectedUser = "";
    var selectedUserID = "";
    var selectedRole = "";
    var Rolesgrid = "";
    var Usersgrid = "";
    var gridRolesToBeAdded = "";
    var myIndex = 0;
    var str = "LastName";
    str.toLowerCase();

    $(document).ready(function () {
        window.location.hash = '#FormTitleHeading';
        $("#UsersMenu")[0].childNodes[0].style.visibility = "visible";
        $("#UsersMenu")[0].childNodes[1].style.visibility = "visible";
        $("#RolesMenu")[0].childNodes[0].style.visibility = "visible";
        $("#RolesMenu")[0].childNodes[1].style.visibility = "visible";
        $("#UsersMenu")[0].childNodes[0].title = "Add New User";
        $("#UsersMenu")[0].childNodes[1].title = "Delete Selected User";
        $("#RolesMenu")[0].childNodes[0].title = "Add Roles to User";
        $("#RolesMenu")[0].childNodes[1].title = "Delete Selected Role";
        Usersgrid = $("#grdUsers").kendoGrid({
            dataSource: {
                type: "application/jsonp",
                transport: {
                    read:
                            {
                                url: "http://" + servername + "/uBillingServices/Security/Security.svc/getUsers",
                                dataType: "json",
                                data: {
                                    LanguageID: 'en'
                                }
                            }
                },
                sort: { field: "LastName"},
                schema: {
                    model: {
                        fields: {
                            UserID: { type: "string" },
                            UserName: { type: "string" },
                            FirstName: { type: "string" },
                            LastName: { type: "string" },
                            AvatarURL: { type: "string" }
                        }
                    }
                }
            },
            dataBound: function (e) {
                row = e.sender.tbody.find(">tr:not(.k-grouping-row)").eq(myIndex);
                if (row.length == 0) {
                    e.sender.select(e.sender.tbody.find(">tr:first"));
                }
                else {
                    e.sender.select(row);
                }
            },
            change: function (arg) {
                var UserIDrow = this.select(),
                  selectedUserx = this.dataItem(UserIDrow).UserName;
                selectedUserID = this.dataItem(UserIDrow).UserID;
                selectedUser = selectedUserx;
                myIndex = this.select().index();
                $('#UserDetailsView').load('<%= Url.Action("EditUser","Administration") %>');

                //                      $.get( '<%= Url.Action("EditUser","Administration") %>', function(data) {
                //                      $('#UserDetailsView').empty();
                //                        $('#UserDetailsView').append(data);
                //                    });
                if (Rolesgrid == "") {
                    Rolesgrid = $("#gridRoles").kendoGrid({
                        dataSource: {
                            type: "application/jsonp",
                            transport: {
                                read:
                                                        {
                                                            url: "http://" + servername + "/uBillingServices/Security/Security.svc/getRoleMembership",
                                                            dataType: "json",
                                                            data: {
                                                                UserName: selectedUser,
                                                                LanguageID: 'en'
                                                            }
                                                        }
                            },
                            sort: { field: "RoleName", dir: "asc" },
                            schema: {
                                model: {
                                    fields: {
                                        RoleID: { type: "string" },
                                        RoleName: { type: "string" }
                                    }
                                }
                            }
                        },
                        change: function (arg) {
                            var selectedr = $.map(this.select(), function (item) {
                                return $(item).text();
                            });
                            selectedRole = selectedr[0];
                        },
                        dataBound: function (e) {
                            e.sender.select(e.sender.tbody.find(">tr:first"));
                        },
                        selectable: "multiple",
                        pageable: false,
                        scrollable: true,
                        navigatable: true,
                        filterable: true,
                        sortable: {
                            mode: "single",
                            allowUnsort: false,
                            field: "LastName"
                        },
                        editable: false,

                        height: 160,
                        columns: [{
                            field: "RoleName",
                            title: "Assigned Roles",
                            headerAttributes: {
                                style: "font-size:small; text-align:center"
                            }, attributes: { style: "text-align:left" }
                        }]
                    });
                }
                else {
                    Rolesgrid.getKendoGrid().dataSource.transport.options.read.data.UserName = selectedUser;

                    var data = [{}];
                    Rolesgrid.getKendoGrid().dataSource.data(data)
                    Rolesgrid.getKendoGrid().dataSource.read();
                }

            },
            selectable: "multiple",
            pageable: false,
            filterable: {
                field: "LastName"

            },
            scrollable: true,
            sortable: {
                field: "LastName",
                mode: "single",
                allowUnsort: false
            },
            editable: false,

            navigatable: true,
            height: 250,
            width: 100,
            rowTemplate: kendo.template($("#rowUsersTemplate").html()),
            columns: [{
                field: "LastName",
                title: "Users", attributes: { style: "text-align:right" }
            }]
        });
        var winNewUser = $("#NewUserWindow").kendoWindow({
            width: "480x",
            height: "450px",
            title: "Add New User",
            content: "/Administration/AddNewUser",
            actions: ["Close"],
            modal: true,
            resizable: false,
            visible: false,
            shadow: false
        }).data("kendoWindow");


        //             var winEditUser = $("#EditUserWindow").kendoWindow({
        //                    width: "480x",
        //                        height: "450px",
        //                        title: "User Details",
        //                       content:"/Administration/EditUser",
        //                        actions: ["Close"],
        //                        modal: false,
        //                        resizable: false,
        //                        visible: false,
        //                        draggable: false,
        //                        animation: false,
        //                }).data("kendoWindow");


    });

    function AddRoletoUser(e) {
        if (e.item.textContent == "+") {

            var win = $("#RolesWindow").kendoWindow({
                width: "505px",
                height: "310px",
                title: "Add Roles to User",
                content: "/Administration/AddUserInRole",
                actions: ["Close"],
                modal: true,
                resizable: false,
                visible: false
            }).data("kendoWindow");

            win.center();
            win.open();

        }
        else if (e.item.textContent == "-") {
            var agree = confirm("Are you sure you want to delete the Assigned Role ?");
            if (agree) {

                jsonData = "UserName=" + selectedUser + "&RoleName=" + selectedRole;
                $.ajax({
                    type: 'GET',
                    crossDomain: true,
                    url: 'http://' + servername + '/uBillingServices/Security/Security.svc/deleteRoleFromUser',
                    dataType: 'jsonp',
                    contentType: "application/json",
                    async: false,
                    data: jsonData,
                    success: function (data) {

                    },
                    error: function (data) {

                    }
                });


                Rolesgrid.getKendoGrid().dataSource.read();

            }
            else
                return false;
        }


    }
    function AddNewUser(e) {
        if (e.item.textContent == "+") {
            var win = $("#NewUserWindow").data("kendoWindow");
            win.refresh();
            win.center();
            win.open();

        }
        else if (e.item.textContent == "-") {
            var agree = confirm("Are you sure you want to delete the User ?");
            if (agree) {
                jsonData = "UserName=" + selectedUser;
                $.ajax({
                    type: 'GET',
                    crossDomain: true,
                    url: 'http://' + servername + '/uBillingServices/Security/Security.svc/deleteUser',
                    dataType: 'jsonp',
                    contentType: "application/json",
                    async: false,
                    data: jsonData,
                    success: function (data) {
                        $("#grdUsers").getKendoGrid().dataSource.read();
                    },
                    error: function (data) {
                        $("#grdUsers").getKendoGrid().dataSource.read();
                    }
                });





            }
            else
                return false;
        }


    }

1 个答案:

答案 0 :(得分:2)

我看到你正在使用kendo ui grid ...

根据此链接,我不熟悉它,不能对不区分大小写的

进行排序

http://www.kendoui.com/forums/ui/grid/how-to-enable-case-insensitive-sorting-on-kendo-ui-grid.aspx

但是有一个黑客可以实现不区分大小写的排序: