简体   繁体   English

ui-grid行具有唯一的ID

[英]ui-grid row to have unique id's

Is it possible to have each row in the ui-grid have a unique id? 是否可以让ui-grid中的每一行都有唯一的ID? Something along the lines of the first row having an id of "row-0" and the second having "row-1" etc 沿第一行的id为“ row-0”的行,第二行为“ row-1”的行,以此类推

So: 所以:

<div class="ui-grid-row" 
    ng-class="{'ui-grid-row-selected': row.isSelected,'ui-grid-tree-header-row': row.treeLevel > -1}" 
    ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" 
    ng-style="Viewport.rowStyle(rowRenderIndex)">
        ...
</div>

Would look something like: 看起来像:

<div class="ui-grid-row" 
    id="row-0"
    ng-class="{'ui-grid-row-selected': row.isSelected,'ui-grid-tree-header-row': row.treeLevel > -1}" 
    ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" 
    ng-style="Viewport.rowStyle(rowRenderIndex)">
        ...
</div>

I have tried the row template but that is setting the id on each cell (probably as expected) 我已经尝试过行模板,但这是在每个单元格上设置ID(可能像预期的那样)

It is so that whilst using Selenium I can select a row by finding it using the id 这样,在使用Selenium时,我可以通过使用ID查找行来选择它

UPDATE: I have now tried setting the Id on the row template to 更新:我现在尝试将行模板上的ID设置为

row-{{rowRenderIndex}}-cell-{{col.uid}}

and this generates something along the lines of 这会产生一些类似的东西

id="row-0-cell-uiGrid-0007"

if I then navigate away from the screen and come back again the id becomes 如果我随后离开屏幕并再次返回,则ID变为

id="row-0-cell-uiGrid-00PW"

If the id was consistent each time then I could use this 如果ID每次都一致,那么我可以使用它

You can use $index 您可以使用$ index

<div class="ui-grid-row" 
    id="{{$index}}"
    ng-class="{'ui-grid-row-selected': row.isSelected,'ui-grid-tree-header-row': row.treeLevel > -1}" 
    ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" 
    ng-style="Viewport.rowStyle(rowRenderIndex)">
        ...
</div>

The row and column together forms a tuple (row,column) which is unique for every cell in the grid. 行和列共同形成一个元组(行,列),该元组对于网格中的每个单元格都是唯一的。 For UI-Grid, there is a way to use this concept. 对于UI-Grid,有一种使用此概念的方法。 Each cell has access to internal scope variable of UI-grid. 每个单元格都可以访问UI-grid的内部范围变量。 In this scope there are two keys 'row' and 'col'. 在此范围内,有两个键“ row”和“ col”。 Each of these has uid property. 每个都有uid属性。 Therefore, use the tuple ('row.uid','col.uid') is always unique for each cell. 因此,使用元组('row.uid','col.uid')对于每个单元格始终是唯一的。 Example of usage (Angular JS): 用法示例(Angular JS):

<div class="ui-grid-cell-contents" trigger-id="{{row.uid + col.uid}}">
{{ COL_FIELD }}</div>

Trigger id is unique for each cell. 触发器ID对于每个单元格都是唯一的。 For multiple grids on same page pass name the grid in scope variable and access it using grid.appScope.gridName 对于同一页面上的多个网格,请在名称范围变量中使用网格,然后使用grid.appScope.gridName对其进行grid.appScope.gridName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM