Hi Telerik,
public DataTable PivotTable(DataTable source)
{
DataTable dest = new DataTable("Pivoted" + source.TableName);
dest.Columns.Add(" ");
foreach (DataRow r in source.Rows)
dest.Columns.Add(r[0].ToString());
for (int i = 0; i < source.Columns.Count - 1; i++) // Columns count should not be decreased by one
{
dest.Rows.Add(dest.NewRow());
}
for (int r = 0; r < dest.Rows.Count; r++)
{
for (int c = 0; c < dest.Columns.Count; c++)
{
if (c == 0)
dest.Rows[r][0] = source.Columns[r + 1].ColumnName; // Row index should not be increased by one
else
dest.Rows[r][c] = source.Rows[c - 1][r + 1]; // Row index should not be increased by one
}
}
dest.AcceptChanges();
return dest;
I think we have found a minor bug in the Pivot Table Sample for RadGrid where the PivotTable() method skips the first column of the table when it converts a vertical table structure to a horizontal structure.
Here is the code:
Please redeem us some points if we are first to report this :).
Regards,
Amir
{
DataTable dest = new DataTable("Pivoted" + source.TableName);
dest.Columns.Add(" ");
foreach (DataRow r in source.Rows)
dest.Columns.Add(r[0].ToString());
for (int i = 0; i < source.Columns.Count - 1; i++) // Columns count should not be decreased by one
{
dest.Rows.Add(dest.NewRow());
}
for (int r = 0; r < dest.Rows.Count; r++)
{
for (int c = 0; c < dest.Columns.Count; c++)
{
if (c == 0)
dest.Rows[r][0] = source.Columns[r + 1].ColumnName; // Row index should not be increased by one
else
dest.Rows[r][c] = source.Rows[c - 1][r + 1]; // Row index should not be increased by one
}
}
dest.AcceptChanges();
return dest;
}