在上一篇中实现了表格的分页,但是表格的高度是随着数据的多少而变化的,无法实现充满浏览器全屏,后来又看了看例子,基本上有三种简单的实现方法
方法一:表格设置固定的高度
最简单的方法,就是给表格设置一个固定的高度,不管浏览器的空白页面有多大,表格只占有固定的高度,不会随数据的多少而变化,在上一个的例子上直接改就可以了。直接设置Height="500" IsFixedHeader="true",设置高度和固定表头,需要注意的是大小写敏感。
<div>
<Table TItem="Test1" PageItemsSource="PageItemsSource" Height="500" IsFixedHeader="true"
IsPagination="true" AllowResizing="true"
IsStriped="true" IsBordered="true"
ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="false"
OnQueryAsync="@OnQueryAsync">
<TableColumns>
<TableColumn @bind-Field="@context.Id" Width="180" />
<TableColumn @bind-Field="@context.内容" />
<TableColumn @bind-Field="@context.名称" />
</TableColumns>
</Table>
</div>
方法二:设置外层div的高度
看了例子,发现如果不设置表格的Height属性,那么表格就属于自动高度,那么我们设置外层的div高度就可以了,想要实现全屏的话设置div高度为100%,此适合于页面中只有一个div且只有一个表格的情况,需要删除表格的Height属性。
<div style="height:100%">
<Table TItem="Test1" PageItemsSource="PageItemsSource" IsFixedHeader="true"
IsPagination="true" AllowResizing="true"
IsStriped="true" IsBordered="true"
ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="false"
OnQueryAsync="@OnQueryAsync">
<TableColumns>
<TableColumn @bind-Field="@context.Id" Width="180" />
<TableColumn @bind-Field="@context.内容" />
<TableColumn @bind-Field="@context.名称" />
</TableColumns>
</Table>
</div>
方法三:多个div的情况
如果页面中有多个div的话,可以给每个div都设置好百分比高度,也是可以实现全屏效果的,如两个div,设置一个高度为10%,另一个高度为90%
<div style=" height:10%">
<Button Text="增加数据" OnClick="ShowData"></Button>
</div>
<div style="height:90%">
<Table TItem="Test1" PageItemsSource="PageItemsSource" IsFixedHeader="true"
IsPagination="true" AllowResizing="true"
IsStriped="true" IsBordered="true"
ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="false"
OnQueryAsync="@OnQueryAsync">
<TableColumns>
<TableColumn @bind-Field="@context.Id" Width="180" />
<TableColumn @bind-Field="@context.内容" />
<TableColumn @bind-Field="@context.名称" />
</TableColumns>
</Table>
</div>
当然也可以使用布局组件来实现更加完美的效果,这里没有试,够用就行了。