|
| 1 | +--- |
| 2 | +title: The TileLayout does not update the HeaderText properly |
| 3 | +description: The TileLayout does not update the HeaderText properly when bound to a property. Why does this happen and how to fix it? |
| 4 | +type: how-to |
| 5 | +page_title: The TileLayout does not update the HeaderText properly |
| 6 | +slug: tilelayout-kb-render-contents |
| 7 | +position: |
| 8 | +tags: |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | +<table> |
| 14 | + <tbody> |
| 15 | + <tr> |
| 16 | + <td>Product</td> |
| 17 | + <td>TileLayout for Blazor</td> |
| 18 | + </tr> |
| 19 | + </tbody> |
| 20 | +</table> |
| 21 | + |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +I have bound the `HeaderText` of the TileLayout to a property in my code. I would like to be able to set its value dynamically based on user action such as a click on a child component (chart series, button, etc.) in the `<Content>` of another Tile. |
| 26 | + |
| 27 | + |
| 28 | +## Solution |
| 29 | + |
| 30 | +When clicking on a child component in the `<Content>` of another tile you initiate a render cycle. In this cycle the page is rendered anew and the components placed inside the `<Content>` are displayed. At this stage the `OnParametersSet` lifecycle hook of the TileLayout is called and the value of the `HeaderText` is updated, but not displayed in the HTML. To inform the UI that it should render again you must use the `StateHasChanged()`, which will change the value of the `HeaderText` in the HTML. |
| 31 | + |
| 32 | +>caption Set the HeaderText based on clicked series of the Chart |
| 33 | +
|
| 34 | +````CSHTML |
| 35 | +@*Click on a Chart Series to change the HeaderText for the Tile*@ |
| 36 | +
|
| 37 | +<TelerikTileLayout Columns="3" |
| 38 | + RowHeight="200px" |
| 39 | + Resizable="true" |
| 40 | + Reorderable="true"> |
| 41 | + <TileLayoutItems> |
| 42 | + <TileLayoutItem HeaderText="Season"> |
| 43 | + <Content> |
| 44 | + <TelerikChart Height="140px" OnSeriesClick="@OnSeasonSeriesClickHandler"> |
| 45 | + <ChartSeriesItems> |
| 46 | + <ChartSeries Type="ChartSeriesType.Bar" Name="Results" Data="@PlayedSeries"> |
| 47 | + <ChartSeriesLabels Visible="true"></ChartSeriesLabels> |
| 48 | + </ChartSeries> |
| 49 | + <ChartSeries Type="ChartSeriesType.Bar" Name="Today" Data="@TodaySeries"> |
| 50 | + <ChartSeriesLabels Visible="true"></ChartSeriesLabels> |
| 51 | + </ChartSeries> |
| 52 | + <ChartSeries Type="ChartSeriesType.Bar" Name="Upcoming" Data="@UpcomingSeries"> |
| 53 | + <ChartSeriesLabels Visible="true"></ChartSeriesLabels> |
| 54 | + </ChartSeries> |
| 55 | + </ChartSeriesItems> |
| 56 | +
|
| 57 | + <ChartCategoryAxes> |
| 58 | + <ChartCategoryAxis Visible="false"></ChartCategoryAxis> |
| 59 | + </ChartCategoryAxes> |
| 60 | +
|
| 61 | + <ChartValueAxes> |
| 62 | + <ChartValueAxis Visible="false"></ChartValueAxis> |
| 63 | + </ChartValueAxes> |
| 64 | +
|
| 65 | + <ChartLegend Position="ChartLegendPosition.Bottom" Spacing="10"> |
| 66 | + </ChartLegend> |
| 67 | + </TelerikChart> |
| 68 | + </Content> |
| 69 | + </TileLayoutItem> |
| 70 | +
|
| 71 | + <TileLayoutItem HeaderText="Panel 2"> |
| 72 | + </TileLayoutItem> |
| 73 | +
|
| 74 | + <TileLayoutItem HeaderText="@ResultPanelHeader" RowSpan="3"> |
| 75 | + <Content> |
| 76 | + <h3>@ResultPanelHeader</h3> |
| 77 | + Show the Results for the clicked series here... |
| 78 | + </Content> |
| 79 | + </TileLayoutItem> |
| 80 | +
|
| 81 | + <TileLayoutItem HeaderText="Panel 4" RowSpan="2" ColSpan="2"> |
| 82 | + </TileLayoutItem> |
| 83 | + </TileLayoutItems> |
| 84 | +</TelerikTileLayout> |
| 85 | +
|
| 86 | +
|
| 87 | +@code { |
| 88 | +
|
| 89 | + public string ResultPanelHeader { get; set; } |
| 90 | +
|
| 91 | + private List<object> PlayedSeries = new List<object>() { 45 }; |
| 92 | + private List<object> TodaySeries = new List<object>() { 10 }; |
| 93 | + private List<object> UpcomingSeries = new List<object>() { 325 }; |
| 94 | +
|
| 95 | + protected override void OnInitialized() |
| 96 | + { |
| 97 | + ResultPanelHeader = "Result Panel"; |
| 98 | + base.OnInitialized(); |
| 99 | + } |
| 100 | +
|
| 101 | + private void OnSeasonSeriesClickHandler(ChartSeriesClickEventArgs args) |
| 102 | + { |
| 103 | + int seriesIndex = args.SeriesIndex; |
| 104 | + string seriesName = args.SeriesName; |
| 105 | +
|
| 106 | + ResultPanelHeader = seriesName; |
| 107 | + |
| 108 | + //call StateHasChanged() to update the ResultPanelHeader in the rendered HTML |
| 109 | + StateHasChanged(); |
| 110 | + } |
| 111 | +} |
| 112 | +```` |
| 113 | + |
| 114 | + |
0 commit comments