Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weird stretchy table issue #11

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/EventLogExpert/Components/EventTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@
<table>
<thead>
<tr>
<th nowrap width="@(_colWidths["RecordId"])px">Rec</th>
<th style="@GetInlineStyle("RecordId")">Rec</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["TimeCreated"])px">Time</th>
<th style="@GetInlineStyle("TimeCreated")">Time</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["Id"])px">Id</th>
<th style="@GetInlineStyle("Id")x">Id</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["MachineName"])px">Machine</th>
<th style="@GetInlineStyle("MachineName")">Machine</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["Level"])px">Level</th>
<th style="@GetInlineStyle("Level")">Level</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["ProviderName"])px">Source</th>
<th style="@GetInlineStyle("ProviderName")">Source</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["Task"])px">Task</th>
<th style="@GetInlineStyle("Task")">Task</th>
<th class="table-divider"></th>
<th nowrap width="@(_colWidths["Description"])px">Description</th>
<th style="@GetDescriptionStyle()">Description</th>
</tr>
</thead>
<tbody>
<Virtualize Items="@EventLogState.Value.EventsToDisplay" Context="evt">
<tr>
<td nowrap>@evt.RecordId</td>
<th class="table-divider"></th>
<td nowrap>@evt.TimeCreated</td>
<th class="table-divider"></th>
<td nowrap>@evt.Id</td>
<th class="table-divider"></th>
<td nowrap>@evt.MachineName</td>
<th class="table-divider"></th>
<td nowrap>@evt.Level</td>
<th class="table-divider"></th>
<td nowrap>@evt.ProviderName</td>
<th class="table-divider"></th>
<td nowrap>@evt.TaskDisplayName</td>
<th class="table-divider"></th>
<td nowrap>@evt.Description</td>
</tr>
</Virtualize>
<Virtualize Items="@EventLogState.Value.EventsToDisplay" Context="evt">
<tr>
<td style="@GetInlineStyle("RecordId")">@evt.RecordId</td>
<th class="table-divider"></th>
<td style="@GetInlineStyle("TimeCreated")">@evt.TimeCreated</td>
<th class="table-divider"></th>
<td style="@GetInlineStyle("Id")">@evt.Id</td>
<th class="table-divider"></th>
<td style="@GetInlineStyle("MachineName")">@evt.MachineName</td>
<th class="table-divider"></th>
<td style="@GetInlineStyle("Level")">@evt.Level</td>
<th class="table-divider"></th>
<td style="@GetInlineStyle("ProviderName")">@evt.ProviderName</td>
<th class="table-divider"></th>
<td style="@GetInlineStyle("Task")">@evt.TaskDisplayName</td>
<th class="table-divider"></th>
<td style="@GetDescriptionStyle()">@evt.Description</td>
</tr>
</Virtualize>
</tbody>
</table>
</div>
</div>
30 changes: 22 additions & 8 deletions src/EventLogExpert/Components/EventTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ public partial class EventTable
{
private readonly Dictionary<string, int> _colWidths = new()
{
{ "RecordId", 10 },
{ "TimeCreated", 25 },
{ "Id", 10 },
{ "MachineName", 10 },
{ "Level", 15 },
{ "ProviderName", 25 },
{ "Task", 20 },
{ "Description", 200 }
{ "RecordId", 75 },
{ "TimeCreated", 165 },
{ "Id", 50 },
{ "MachineName", 100 },
{ "Level", 100 },
{ "ProviderName", 250 },
{ "Task", 150 }
};

private const int TableDividerWidth = 4;

private const int ScrollBarWidth = 18;

private string GetDescriptionStyle()
{
var total = _colWidths.Values.Sum() + (TableDividerWidth * _colWidths.Count) + ScrollBarWidth;
return $"min-width: calc(100vw - {total}px); max-width: calc(100vw - {total}px);";
}

private string GetInlineStyle(string colName)
{
return $"min-width: {_colWidths[colName]}px; max-width: {_colWidths[colName]}px;";
}
}
9 changes: 5 additions & 4 deletions src/EventLogExpert/Components/EventTable.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@

table {
border-spacing: 0;
width: calc(100% - 10px);
table-layout: fixed;
}

tr:nth-child(odd) {
background-color: var(--background-darkgray);
}

th {
white-space: nowrap;
overflow: hidden;
position: sticky;
top: 0;
background-color: var(--background-darkgray);
z-index: 2;
}

td {
white-space: nowrap;
overflow: hidden;
}

.table-divider {
width: 1px;
min-width: 4px;
max-width: 4px;
margin: 0;
padding: 0;
background: var(--clr-black);
Expand Down