是否可以使用 Angular UI Grid 将列的排序绑定到与其显示属性不同的属性? [英] Is it possible to bind the sorting of a column to a different property than its display property with Angular UI Grid?

查看:18
本文介绍了是否可以使用 Angular UI Grid 将列的排序绑定到与其显示属性不同的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有人知道使用 Angular UI Grid 以与另一列相同的顺序对列进行排序的方法.

I was just wondering if anyone knew of a way to sort a column in the same order as another column using Angular UI Grid.

推荐答案

我猜你的意思是,如果(例如)你有分别显示名字和姓氏的名字"和姓氏"列,你想点击姓氏"排序,这实际上是按照名字"的顺序对表格进行排序?

I'm guessing you mean that if (for example) you have "First Name" and "Last Name" columns which display first name and last name respectively, you want to click sort on "Last Name" and this actually sorts the table in order of "First Name"?

如果是这样,您可以使用单元格模板来完成此操作.

If so, you can accomplish this using a cell template.

假设您有下表:

当您对姓氏"列进行排序时,它实际上会按照名字"列中的数据顺序对表格进行排序.

and when you sort the "Last Name" column it will actually sort the table in order of the data in the "First Name" column.

假设数据如下:

$scope.gridOptions.data = [{
    "firstName": "David",
    "lastName": "Carney",
}, {
    "firstName": "Bob",
    "lastName": "Wise",
}, {
    "firstName": "Peter",
    "lastName": "Thompson",
}];

如下定义您的columnDefs:

$scope.gridOptions.columnDefs = [{
    name: 'firstName',
    field: 'firstName'
}, {
    name: 'lastName',
    field: 'firstName',
    cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.lastName}}</div>'
}];

第二列的列定义将列命名为Last Name",单元格模板确保 lastName 属性显示在单元格中,但是作为列的 field绑定到 firstName 这意味着当列被排序时,它会在 firstName 上排序.

The column definition for the second column names the column "Last Name" and the cell template ensures the lastName attribute is displayed in the cell, however as the column's field is bound to firstName it means when the column is sorted it is sorted on firstName.

可以在此处找到示例.对第二列(姓氏)进行排序,实际上将按照第一列(名字)的顺序对行进行排序.

An example can be found here. Sort the second column (Last Name) and the rows will actually be sorted in order of the first column (First Name).

这篇关于是否可以使用 Angular UI Grid 将列的排序绑定到与其显示属性不同的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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