UI-未在可扩展网格上调用网格 SortChanged

UI-Grid SortChanged not called on expandable grid

UI-网格:v3.2.1

尝试对扩展网格中的列进行排序时,我注意到该列没有调用我们的 SortChanged 回调。

我们将外部排序与可扩展网格结合使用。

我们通过以下调用设置排序

controller.gridOptions = {
  data: controller.myData,
  enableHorizontalScrollbar: 0,
  enableVerticalScrollbar: 0,
  useExternalSorting: true,
  expandableRowTemplate: urls.SubGridTemplate,
  enableGridMenu: true,
  rowHeight: gridRowHeight,
  minRowsToShow: minRowsToShow,
  enableFiltering: true,
  useExternalFiltering: true,
  enableSelectionModeToggle: true,
  columnDefs: templates.getGridColumnDefinitions(
    { advancedFilterChanged: advancedFilterChanged },
    controller.gridSettings
  )
};

然后

angularGridApi.core.on.sortChanged($scope, sortChanged);

然后我们使用

设置可扩展网格
  angularGridApi.expandable.on.rowExpandedStateChanged(
    $scope,
    retrieveDetailRows
  );

可扩展网格似乎没有使用 $scope.core.on.sortChanged($scope, sortChanged)

在我的例子中,由于这个警告,默认排序算法默认为字符串。

"The sort algorithm is chosen based on the column type. ui-grid will guess the type based on the data, although if you load data asynchronously after the columns it will often decide all your columns are string." Sorting Documentation

明确设置列类型为我解决了这个问题。

{
  field: "myDataField",
  displayName: "My Column Header",
  type: "number",
  minWidth: 93,
  maxWidth: 120
}

如果您需要更复杂的排序,您可以在每一列上设置自定义排序。