Last active
August 31, 2021 21:08
-
-
Save fluxdigital/55862f41265b03cdf6bbe56e74b263be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits MyWebsite.Models.ITable | |
@{ | |
var tableRowsToSkip = 0; | |
if (DataSource.HasHeaderRow) | |
{ | |
tableRowsToSkip = 1; | |
} | |
var tableRowsToRemove = 1; | |
if (DataSource.HasFooterRow && DataSource.HasHeaderRow) | |
{ | |
tableRowsToRemove = 2; | |
} | |
else if (DataSource.HasFooterRow) | |
{ | |
tableRowsToRemove = 1; | |
} | |
else | |
{ | |
tableRowsToRemove = 0; | |
} | |
} | |
<!--start table --> | |
<div class="table"> | |
<table class="table__table"> | |
@if (this.DataSource != null) | |
{ | |
if (this.DataSource.TableRows != null && this.DataSource.TableRows.Any()) | |
{ | |
if (DataSource.HasHeaderRow) | |
{ | |
<thead> | |
<tr> | |
@foreach (var headerCell in DataSource.TableRows.ToList().First().TableCells) | |
{ | |
<th>@Editable(headerCell, x => x.Text)</th> | |
} | |
</tr> | |
</thead> | |
} | |
<tbody> | |
@foreach (var tableRow in this.DataSource.TableRows.Skip(tableRowsToSkip).Take(DataSource.TableRows.Count()-tableRowsToRemove)) | |
{ | |
<tr> | |
@foreach (var tableCell in tableRow.TableCells) | |
{ | |
<td>@Editable(tableCell, x => x.Text)</td> | |
} | |
</tr> | |
} | |
</tbody> | |
if (DataSource.HasFooterRow) | |
{ | |
<tfoot> | |
<tr> | |
@foreach (var footerCell in DataSource.TableRows.ToList().Last().TableCells) | |
{ | |
<td>@Editable(footerCell, x => x.Text)</td> | |
} | |
</tr> | |
</tfoot> | |
} | |
} | |
else if (Sitecore.Context.PageMode.IsExperienceEditorEditing) | |
{ | |
<div class="message"> | |
<h2>No Table Rows</h2> | |
<p>No Table Rows have been created for this Table. </p> | |
</div> | |
} | |
} | |
else if (Sitecore.Context.PageMode.IsExperienceEditorEditing) | |
{ | |
<div class="message"> | |
<h2>No datasource Set</h2> | |
<p>Please select a datasource for this Table.</p> | |
</div> | |
} | |
</table> | |
</div> | |
<!--end table --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment