0

我已经在我的 jqgrid 中使用“json”数据声明了这一点:

sortname: 'CascadeId',
sortorder: 'asc',
sortable: true,

但排序按钮不起作用。我已经用asp实现了服务器端排序。但按钮不起作用。你能指出如何启用按钮吗?

更新: 初始 GET 请求:

http://localhost/myHandler.ashx?_search=false&nd=1361795033464&rows=20&page=1&sidx=CascadeId&sord=asc

Col型号:

colModel: [ { name: 'CascadeId', index: 'CascadeId', width: 85, sortable: true, editable: true, editrules: { custom: true, custom_func: validateCascadeID, required: true} }, { name: 'VenuProfile', index: 'VenuProfile', width: 150, sortable: false, editable: true, edittype: 'select', editoptions: { value: VenuProfile, width: 90, align: 'left'} }, { name: 'Location', index: 'Location', width: 210, sortable: false, editable: true }, ]

4

1 回答 1

1

如果您在 POST sidx&中看到排序信息,sord并且您正在服务器上接收这些值(再次sidx& sord),那么您需要order by在服务器获取数据时执行等效操作。

例如,在 C# 中order by,数据的分页请求如下所示:

var pagedQuery = dataset.OrderBy(sidx + " " + sord).Skip((page - 1) * rows).Take(rows);

编辑我的一个工作网格的一部分,它以DateTimeMail' column indesc 顺序的排序开始。

客户端:

        $('#Mailbox').jqGrid({
            datatype: 'json',
            url: '/Mail/MailboxGetGridData',
            mtype: 'POST',
            autoencode: true,
            postData: { Mailbox: 'Inbox' },
            colNames: ['IdMail', 'From', 'To', 'Date / Time', 'Subject', 'Message', 'HasBeenRead'],
            colModel: [
                { name: 'IdMail', index: 'IdMail', width: 95, align: 'center', sortable: false, hidden: true, editable: false },
                { name: 'IdSender', index: 'IdSender', width: 150, align: 'center', sortable: true, firstsortorder: 'desc', hidden: false, editable: false },
                { name: 'IdRecipient', index: 'IdRecipient', width: 150, align: 'center', sortable: true, firstsortorder: 'desc', hidden: false, editable: false },
                { name: 'DateTimeMail', index: 'DateTimeMail', width: 150, align: 'center', sortable: true, firstsortorder: 'desc', hidden: false, editable: false },
                { name: 'Subject', index: 'Subject', width: 250, align: 'left', sortable: false, hidden: false, editable: false },
                { name: 'Message', index: 'Message', width: 150, align: 'center', sortable: false, hidden: true, editable: false },
                { name: 'HasBeenRead', index: 'HasBeenRead', width: 150, align: 'center', sortable: false, hidden: true, editable: false },
            ],
            pager: $('#MailboxPager'),
            rowNum: 5,
            rowList: [5, 10, 20, 50],
            sortname: 'DateTimeMail',
            sortorder: "desc",
....

服务器端:

    public ActionResult MailboxGetGridData(string sidx, string sord, int page, int rows, bool _search, string filters)
{
  .....
  var pagedQuery = filteredQuery.OrderBy(sidx + " " + sord).Skip((page - 1) * rows).Take(rows);
  var jsonData = new
            {
                total = (totalRecords + rows - 1) / rows,
                page = page,
                records = totalRecords,
                rows = (
                    from item in pagedQuery.ToList()
                    select new
                    {
                        cell = new string[] {
                            item.IdMail.ToString(),
                            HelperClasses.HelperMethods.getUserName(item.IdSender),
                            HelperClasses.HelperMethods.getUserName(item.IdRecipient),
                            ((DateTime)item.DateTimeMail).ToString("g"),
                            item.Subject,
                            item.Message,
                            (Mailbox == "Inbox") ? item.HasBeenRead.ToString() : "True"
                        }
                    }).ToArray()
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);
于 2013-02-25T11:57:24.563 回答