如何获得行索引的角度UI电网3.0 [英] How to get row index in angular ui-grid 3.0

查看:258
本文介绍了如何获得行索引的角度UI电网3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与棱角分明的UI网3.0版本的工作,并不能找到获得该行的索引的方式,一个记数列添加到网格中。
我想帮助我。

I'm working with angular ui-grid version 3.0 and can not find the way to get the index of the row, to add a numeration column to the grid. I would like to help me.

推荐答案

有没有一种方式来获得该行的指数容易,所以这取决于你想要做什么。你期望的编号做当有人对数据进行排序? - 你想要的号码留下来,因为他们在原来的数据,或做你想让他们改变和调整,以新的排序顺序

There isn't a way to get the index of the row easily, so it depends what you're trying to do. What do you expect the numbering to do when someone sorts the data - do you want the numbers to stay as they were in the original data, or do you want them to change and align to the new sort order?

在常见问题解答 http://ui-grid.info/docs/#/tutorial/499_FAQ我们发现:

In the FAQ http://ui-grid.info/docs/#/tutorial/499_FAQ we find:

这里的问题是你真正想要的目的。你想实际的行索引,或要显示所有行的顺序编号?

The question here is what you're really trying to achieve. Do you want the actual row index, or that you want to display a sequential id in all your rows?

如果是后者,那么你可以只需添加计数器列到您的数据做到这一点:

If the latter, then you can do it by just adding a counter column to your data:

$scope.myData.forEach( function( row, index){
  row.sequence = index;
});

如果你想显示网格内部内的行的索引,那么它取决于你想要的内部。可以得到grid.rows内的行的索引,这将显示行,因为它代表在原始行表(未过滤也不排序),或行的内grid.renderContainers.body.visibleRowCache索引(过滤并排序)或当前显示的行内呈现的行的索引(给定的虚拟化,这通常是一个特别无用数)。

If you want to show the index of the row within the grid internals, then it depends on which internal you want. You can get the index of the row within grid.rows, which would show the row as it stands in the original rows list (not filtered nor sorted), or the index of the row within grid.renderContainers.body.visibleRowCache (filtered and sorted), or the render index of the row within the currently displayed rows (given virtualisation, this is generally a particularly useless number).

如果你没事,只要有人排序或过滤器则数字会发生变化,那么你可以用cellTemplate,这将是这样做的:

If you're OK that whenever someone sorts or filters then the numbers will change, then you could do it with a cellTemplate, which would be something like:

cellTemplate: '<div class="ui-grid-cell-contents">{{grid.renderContainers.body.visibleRowCache.indexOf(row)}}</div>'

这篇关于如何获得行索引的角度UI电网3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆