Angular UI-Grid 枢轴 [英] Angular UI-Grid Pivot
问题描述
我有这些 Javascript 对象的集合:(显示为 DTO)
I have a collection of these Javascript objects: (Displayed as a DTO)
public class ParameterValueDTO : DataTransferObject
{
public int Id { get; set; }
public String Comments { get; set; }
public String Description { get; set; }
}
默认情况下,AngularJS UI-Grid 将为每个 ParameterValue 对象创建一行,其中包含 3 列:Id、Comments、Description,这可以正常工作.
By default, AngularJS UI-Grid will create a row for each ParameterValue object with 3 columns: Id, Comments, Description which works fine.
然而,我想做的是为每个对象的评论"值创建一列,并将其绑定到相应的描述"值.基本上是旋转表格,所以它只有 1 行(暂时忘记 ID 列).
What I would like to do however is create a column for each object's "Comments" value and bind it to the corresponding "Description" value. Essentially pivoting the table so it only has 1 row (forget the ID column for now).
我尝试过的 javascript:
The javascript I've tried:
var cols = [];
var row = obj.data.ProductAttributes[0].Specifications[0].ParameterValues
var length = row.length;
for (var i = 0; i < length; i++) {
cols.push({
field: "Description",
displayName: row[i].Comments
});
}
$scope.gridOptions = {
columnDefs: cols,
data: row
};
以上结果显然是错误的:
The above results in the following which is obviously wrong:
是否可以使用当前的数据结构来实现这一点,或者我应该采取的正确方法是什么?
Is it possible to accomplish this with the current data structure or what exactly is the correct approach I should be taking?
推荐答案
我会修改代码以重新处理您的数据.ui-grid真的只喜欢绑定列和行,不能颠倒顺序.
I'd modify the code to just reprocess your data. ui-grid really only likes to bind to columns and rows, it can't reverse the order.
所以你会:
var pivotData = [ {} ];
data.forEach(function(parameterDTO) {
pivotData[0][parameterDTO.comments] = parameterDTO.description;
});
然后您应该能够使用该新数据对象作为网格数据.
Then you should be able to use that new data object as grid data.
这篇关于Angular UI-Grid 枢轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!