简体   繁体   English

将表列表按列名分​​组(包括示例)

[英]group a table list by a column name (sample included)

i have a table that i need to group into divs 我有一张需要分组的表格

rated | rater | team | score | subject
john    mike     TA     10      math
john    mike     TA     10      PE
john    jane     TA     9       math
john    jane     TA     9       PE
kim     lee      TB     5       math
kim     min      TB     2       math

i need it to look like 我需要它看起来像

 TA
    john
     RATER    MATH  PE         
     mike      10   10
     jane      9     9
 TB
   kim
    RATER     MATH  PE
    lee        5
    min        2

In my view I'm just iterating these values from a LINQ with a 在我看来,我只是在LINQ中使用

@foreach (var item in Model) 

Any help would be appreciated. 任何帮助,将不胜感激。

It looks like you want to transpose the columns and rows. 看来您想转置列和行。

Check out this method from this blog: http://higherlogics.blogspot.com/2010/05/linq-transpose-extension-method.html 在以下博客中查看此方法: http : //higherlogics.blogspot.com/2010/05/linq-transpose-extension-method.html

Here's the code sample: 这是代码示例:

public static IEnumerable<IEnumerable<T>> Transpose<T>(
     this IEnumerable<IEnumerable<T>> source)
{
return from row in source
       from col in row.Select(
           (x, i) => new KeyValuePair<int, T>(i, x))
       group col.Value by col.Key into c
       select c as IEnumerable<T>;
}

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

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