如何在用户仅在 ui-grid 上选择行后绑定



我正在使用角度ui-grid进行动态数据加载。我可以从用户行选择选项中获取控制台结果。最初UI-grid已经加载了数据,在用户行选择之后,仅加载了选定的行。请告诉我如何实现此功能。我使用以下代码获得了行选择结果;

columnDefs:  columnNames.map(colName => {
        return {
          name: colName,
          type: DefaultTableColumnType,
          cellTemplate: `
            <div ng-click="grid.appScope.clickHandler(row)" ng-if="!grid.getCellValue(row, col).startsWith('%html')"
                 class="ui-grid-cell-contents">
              {{grid.getCellValue(row, col)}}
            </div>
            <div  ng-click="grid.appScope.clickHandler(row)" ng-if="grid.getCellValue(row, col).startsWith('%html')"
                 ng-bind-html="grid.getCellValue(row, col).split('%html')[1]"
                 class="ui-grid-cell-contents">
            </div>
          `,
        }
      }),
    appScopeProvider: {
                    clickHandler: function onCellClick(row) {
    console.log("Entered");
        console.log(row.entity);
      }

您所要做的就是更改使用仅包含该元素的新数组填充表的数据。

如果您使用 $scope.data = [...];

那么应该是:

appScopeProvider: {
      clickHandler: function onCellClick(row) {
        console.log(row.entity);
        $scope.data = [row.entity];
      }
  }

最新更新