Category / Section
How to customize the OLAPGrid cells?
1 min read
You can hide columns and rows in OlapGrid using cells RemoveAt() method. You can refer to the following code examples.
C#
protected void Page_Init(object sender, EventArgs e) { this.OlapGrid1.RowBound += new eventHandler<RowBoundEventArgs>(OlapGrid1_RowBound); } void OlapGrid1_RowBound(object sender, RowBoundEventArgs e) { if (e.GridRow.Cells.Count > 2) e.GridRow.Cells.RemoveAt(2); if (((e.GridRow as TableRow).Parent as Table).Rows.Count == this.OlapGrid1.OlapDataManager.PivotEngine.TableColumns[0].Cells.Count) ((e.GridRow as TableRow).Parent as Table).Rows.RemoveAt(3); }
VB
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) AddHandler OlapGrid1.RowBound, AddressOf OlapGrid1_RowBound End Sub Private Sub OlapGrid1_RowBound(ByVal sender As Object, ByVal e As RowBoundEventArgs) If e.GridRow.Cells.Count > 2 Then e.GridRow.Cells.RemoveAt(2) End If If (TryCast((TryCast(e.GridRow, TableRow)).Parent, Table)).Rows.Count = Me.OlapGrid1.OlapDataManager.PivotEngine.TableColumns(0).Cells.Count Then (TryCast((TryCast(e.GridRow, TableRow)).Parent, Table)).Rows.RemoveAt(3) End If End Sub
Add/Insert Columns/Rows
You can add/insert columns/rows using the RowBound event. You can refer to the following code examples.
C#
protected void Page_Init(object sender, EventArgs e) { this.OlapGrid1.RowBound += new eventHandler<RowBoundEventArgs>(OlapGrid1_RowBound); } void OlapGrid1_RowBound(object sender, RowBoundEventArgs e) { if (e.GridRow.Cells.Count > 5) e.GridRow.Cells.AddAt(5, new TableCell() { Text = "NewValue", Width = Unit.Parse("20px") }); if (((e.GridRow as TableRow).Parent as Table).Rows.Count == this.OlapGrid1.OlapDataManager.PivotEngine.TableColumns[0].Cells.Count) ((e.GridRow as TableRow).Parent as Table).Rows.AddAt(2, new TableRow() { Height = Unit.Parse("20px"), Width = Unit.Parse("50px") }); }
VB
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) AddHandler OlapGrid1.RowBound, AddressOf OlapGrid1_RowBound End Sub Private Sub OlapGrid1_RowBound(ByVal sender As Object, ByVal e As RowBoundEventArgs) If e.GridRow.Cells.Count > 5 Then e.GridRow.Cells.AddAt(5, New TableCell() With {.Text = "NewValue", .Width = Unit.Parse("20px")}) End If If (TryCast((TryCast(e.GridRow, TableRow)).Parent, Table)).Rows.Count = Me.OlapGrid1.OlapDataManager.PivotEngine.TableColumns(0).Cells.Count Then (TryCast((TryCast(e.GridRow, TableRow)).Parent, Table)).Rows.AddAt(2, New TableRow() With {.Height = Unit.Parse("20px"), .Width = Unit.Parse("50px")}) End If End Sub
Changing values in an existing cell
You can update cell values using the cells Text property via RowBound event. You can refer to the following code examples.
C#
void OlapGrid1_RowBound(object sender, RowBoundEventArgs e) { if(e.GridRow.Cells.Count>1) e.GridRow.Cells[0].Text = "SomeText"; }
VB
Private Sub OlapGrid1_RowBound(ByVal sender As Object, ByVal e As RowBoundEventArgs) If e.GridRow.Cells.Count>1 Then e.GridRow.Cells(0).Text = "SomeText" End If End Sub
Adding hyperlinks as well as passing information to cells
You can set the hyperlink for value cells, row header and column header as well as pass information via its PivotCellDescriptior property. You can refer to the following code examples.
C#
this.OlapGrid1.EnableHyperLinkValueCell = true; this.OlapGrid1.EnableHyperLinkRowHeader = true; this.OlapGrid1.EnableHyperLinkColumnHeader = true; this.OlapGrid1.HyperlinkCellClick += new Syncfusion.Web.UI.WebControls.Grid.Olap.OlapGrid.RaiseHyperlinkCellClick(OlapGrid1_HyperlinkCellClick); void OlapGrid1_HyperlinkCellClick(object sender, Syncfusion.Web.UI.WebControls.Grid.Olap.HyperlinkCellClickArg e) { e.PivotCellDescriptor.CellValue = "NewValueOnClick"; }
VB
Me.OlapGrid1.EnableHyperLinkValueCell = True Me.OlapGrid1.EnableHyperLinkRowHeader = True Me.OlapGrid1.EnableHyperLinkColumnHeader = True AddHandler OlapGrid1.HyperlinkCellClick, AddressOf OlapGrid1_HyperlinkCellClick void OlapGrid1_HyperlinkCellClick(Object sender, Syncfusion.Web.UI.WebControls.Grid.Olap.HyperlinkCellClickArg e) e.PivotCellDescriptor.CellValue = "NewValueOnClick"