1

我有一个清单,我正在对其进行排序

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


    }
4

1 回答 1

2

i see you are using kendo ui grid...

i'm not familiar with it by according to this link it is not possible to sort case insensitive

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

but there is a hack there to achieve case insensitive sorting:

于 2012-12-27T08:32:13.240 回答