【问题标题】:How to get the rowcol object of a cell DOM element selected in the grid of UIGrid?如何获取在 UIGrid 的网格中选择的单元格 DOM 元素的 rowcol 对象?
【发布时间】:2016-05-27 13:09:35
【问题描述】:

我正在使用 UIGrid。 如何获取网格中选定单元格的 DOM 元素的行列对象?

$(".ui-grid-cell-focus") 这将为您提供当前聚焦/选定单元格的 HTML DOM。我正在尝试使用此 HTML DOM 值获取 uiGrid row-col 对象。我不知道怎么做!

【问题讨论】:

  • 你想获取值对象还是实际的dom?你能展示你尝试过的东西吗(代码)
  • @CodingNinja,我已经更新了我的问题。谢谢

标签: angularjs angular-ui-grid


【解决方案1】:

请尝试如下所示。

js

 var editCellTemplate = '<div class="ngCellText"><button class="btn btn-icon-only 
green height-28" ng-click="grid.appScope.editProperty(row.entity.id)"><i 
class="fa fa-edit"></i></button></div>';

        vm.yourGridOptions = {
                    appScopeProvider: vm,
                    flatEntityAccess: false,
                    fastWatch: true,
                    showHeader: false,
                    columnDefs: [
                        {
                            name: 'id',
                            field: 'id',
                            width: 240,
                        },
                        {
                            name: 'Edit',
                            cellTemplate: editCellTemplate,
                            width: 40,
                        }
                    ],
                    data: []
                };

                //edit property
                vm.editProperty = function (id) {
                  // your logic here
                };

【讨论】:

  • 感谢您的回复。然而,这不是我所期待的。我期待的是 rowCol 对象,它是包含行对象和列对象的当前单元格的 JS 对象。不处理数据,但更多处理 UIGrid 的行列信息。
【解决方案2】:

您可以尝试在您的 gridOptions 声明中:

onRegisterApi: function(gridApi){
  gridApi.cellNav.on.navigate($scope,function(newRowcol, oldRowCol){      
    console.log(newRowcol);
  });
}

请务必将 ui.grid.cellNav 注入到您的角度模块中,并在您的网格指令视图中注入 ui-grid-cellNav。 newRowcol 是你的 row-col 对象

【讨论】:

    猜你喜欢
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    相关资源
    最近更新 更多