使用Angular UI-Grid,如何在不使用行选择的情况下访问行实体数据?

时间:2022-05-26 10:37:35

I am trying to switch from Smart-Table version 1.x to Angular ui-grid (version 3.0), the replacement for ng-grid.
I like nearly everything about ui-grid, but one thing is driving me crazy. In smart-table, there is a value for dataRow, which is a convenient way of referencing the entity within a table.

我正在尝试从Smart-Table版本1.x切换到Angular ui-grid(版本3.0),替换ng-grid。我几乎喜欢关于ui-grid的一切,但有一件事让我发疯。在智能表中,dataRow有一个值,这是一种在表中引用实体的便捷方式。

What I was using it for was populating an html template to include field information from the entity, something like ng-click="$parentScope.edit(dataRow.id)" within the html template placed within a grid cell.

我使用它的是填充html模板以包含来自实体的字段信息,例如放置在网格单元格内的html模板中的ng-click =“$ parentScope.edit(dataRow.id)”。

However, in ui-grid, I can't seem to access the entity object without making a formal row or cell selection. Any effort to include it in a cell template results in an object, (row.entity) but I cannot access any of the entity elements, they show up as undefined. Any ideas?

但是,在ui-grid中,如果不进行正式的行或单元格选择,我似乎无法访问实体对象。将它包含在单元格模板中的任何努力都会产生一个对象(row.entity)但我无法访问任何实体元素,它们显示为未定义。有任何想法吗?

Furthermore, I have been able to execute a method in an html template, but only ones with no parameters, not one trying to use a parameter from the entity itself.

此外,我已经能够在html模板中执行一个方法,但只能在没有参数的情况下执行,而不是尝试使用实体本身的参数。

Here is my html template that was working with smart-table:

这是我使用smart-table的html模板:

<a data-toggle="tooltip" data-placement="top" title="View    {{filteredRowCollection}}"   ng-click="$parent.$parent.$parent.$parent.view(dataRow.id)"
   class="glyphicon glyphicon-camera green">
</a>
<a data-toggle="tooltip" data-placement="top" title="Edit {{selectionId}}" ng-click="grid.appScope.edit(row.entity.id)"
   class="glyphicon glyphicon-pencil blue">
</a>
<a data-toggle="tooltip" data-placement="top" title="Delete {{selectionId}}"  ng-click="$parent.$parent.$parent.$parent.delete(dataRow.id)"
   class="glyphicon glyphicon-trash red">
</a>

I was trying to use something like this with ui-grid:

我试图用ui-grid这样的东西:

function edit(row){
    . . .
};

row, at this point is an object, as is row.entity. I expected to be able to use something like row.entity.id, one of the fields, but it is undefined.

行,此时是一个对象,就像row.entity一样。我希望能够使用row.entity.id这样的字段之一,但它是未定义的。

1 个解决方案

#1


4  

This post can be useful, https://technpol.wordpress.com/2014/08/23/upgrading-to-ng-grid-3-0-ui-grid/

这篇文章很有用,https://technpol.wordpress.com/2014/08/23/upgrading-to-ng-grid-3-0-ui-grid/

Basically, you need to set External scope for your grid, so that you can access data.

基本上,您需要为网格设置外部范围,以便您可以访问数据。

#1


4  

This post can be useful, https://technpol.wordpress.com/2014/08/23/upgrading-to-ng-grid-3-0-ui-grid/

这篇文章很有用,https://technpol.wordpress.com/2014/08/23/upgrading-to-ng-grid-3-0-ui-grid/

Basically, you need to set External scope for your grid, so that you can access data.

基本上,您需要为网格设置外部范围,以便您可以访问数据。