jqGrid ASP.NET MVC4初始排序

时间:2012-11-28 10:35:44

标签: asp.net-mvc-4 jqgrid-asp.net

我在Windows MVC4中使用jqGrid作为TreeGrid,但有一个问题:

我的模特:

OrdersGrid = new JQGrid
                {
                   Columns = new List<JQGridColumn>()
                     {
                        new JQGridColumn
                       {
                         DataField = "MeasureId",
                         // always set PrimaryKey for Add,Edit,Delete operations
                         // if not set, the first column will be assumed as primary key
                         PrimaryKey = true,
                         Visible = false,
                         Sortable = false
                       },
                       new JQGridColumn
                       {
                         DataField = "Name",
                         Width = 100,
                         Sortable = true
                       },
                      new JQGridColumn
                      {
                         DataField = "Symbol",
                         Width = 100
                      },
                      },
                         Width = Unit.Pixel(640),
                         Height = Unit.Percentage(100),
                         TreeGridSettings = new TreeGridSettings
                         {
                           Enabled = true
                         },
                         SortSettings = new SortSettings
                         {
                           AutoSortByPrimaryKey = false,
                           InitialSortColumn = "Name",
                           InitialSortDirection = SortDirection.Asc
                          }
                         };

我的控制器:

public JsonResult DataRequested()
  {
     // Get both the grid Model and the data Model
    // The data model in our case is an autogenerated linq2sql database based on Northwind.
       var gridModel = new NavigatorModel();
       ...
       var hierarchyRows = from measure in measures
       select new
       {
           MeasureId = measure.MeasureId,
           Name = measure.Name,
           Symbol = measure.Symbol,
          //ParentID = measure.ParentMeasureId != null ? measure.ParentMeasureId.ToString() : "",
            tree_loaded = true,
            tree_parent = measure.ParentMeasureId,
            tree_level =LoadAllRowsExpanded_GetRowLevel(measure.ParentMeasureId, measures),
            tree_leaf = LoadAllRowsExpanded_IsLeafRow(measure.MeasureId, measures),
            tree_expanded = true
        };

           //var dataModel = new 
          // return the result of the DataBind method, passing the datasource as a parameter
         // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
           return gridModel.OrdersGrid.DataBind(hierarchyRows.AsQueryable());
    }

如上所述,您可以看到我将AutoSortByPrimaryKey设置为false,但是当页面加载时,网格看起来像这样:

jqGrid wrong sorting

当我点击其中一列(名称或符号)进行排序时,一切都变得很好 - 错误显示的测量值位于其父级下方。 我也试过事件来排序“gridInitialize”但也没有成功。 有什么想法吗?

0 个答案:

没有答案