4

我将 jqGrid 用作带有 ASP.NET MVC4 的 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错误排序

当我单击其中一列(名称或符号)进行排序时,一切都变得很好 - 错误显示的 Measure 在它的父项下。我也尝试使用事件在“gridInitialize”之后排序,但也没有成功。有任何想法吗?

4

0 回答 0