|
@using Syncfusion.Blazor.Grids
@inject IJSRuntime JSRuntime
<SfGrid DataSource="@Orders" AllowPaging="true">
<GridEvents DataBound="Bound" TValue="Order"></GridEvents>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<FooterTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
<div id="total">Total: </div> <div style="position: absolute; right: 10px;">@aggregate.Sum</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
. . .
public void Bound()
{
JSRuntime.InvokeAsync<object>("moveElement"); //calling JS function using Interop
}
} |
|
[InteropFile.js]
function moveElement() {
var ele = document.getElementById('total'); //get total text element using id
document.querySelectorAll('.e-summarycell')[0].append(ele); //appended the text to first summary cell
} |
|
[_Host.cshtml]
<head>
. . .
<link rel='nofollow' href="_content/Syncfusion.Blazor/styles/fabric.css" rel="stylesheet" />
<script src="~/InteropFile.js"></script>
</head> |
|
|
Dear Rahul,
Is there some way to make the totals appear like this on the top of each other along with the gray background at footer?
|
[Index.razor]
@using Syncfusion.Blazor.Grids
@inject IJSRuntime JSRuntime
<SfGrid @ref="Grid" ID="Grid" DataSource="@Orders" AllowPaging="true">
<GridEvents DataBound="Bound" TValue="Order"></GridEvents>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<FooterTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
<div>
<div id="total">Total: </div> <div style="position: absolute; right: 10px;">@aggregate.Sum</div>
</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
. ..
public async Task Bound()
{
await JSRuntime.InvokeAsync<object>("moveElement", Grid.ID); //calling JS funcion using Interop
}
} |
|
[InteropFile.js]
function moveElement(id) {
var ele = document.getElementById('total');
document.querySelectorAll('.e-summarycell')[0].append(ele);
var grid = document.getElementById(id);
var aggregateElement = grid.querySelector(".e-gridfooter");
grid.insertBefore(aggregateElement, grid.querySelector(".e-gridcontent"));
} |
|
[_Host.cshtml]
<head>
. . .
<link rel='nofollow' href="_content/Syncfusion.Blazor/styles/fabric.css" rel="stylesheet" />
<script src="~/InteropFile.js"></script>
</head> |
|
|
Dear Rahul,
This is not what I want. I want the totals to appear below the Grid in the footer in vertical order but I want all the totals like:
Tax: 100
Net Total: 900
Gross Total: 1000
Currently the totals become like in the image under each column in mobile which I don't want.
|
<style>
.e-grid .e-summarycell {
word-wrap: unset;
}
</style> |
Would this solution work when there are two grids on one page? I am trying to add a "Total" label on two different grids, but it moves them to the 1st grid only. How can I specify which grid the label should be moved on?
Hi Adam,
We recommend using a unique ID for each grid in order to effectively customize
the grid based on your requirement using CSS. If you have any further questions
or concerns, please get back to us.
Regards,
Sarvesh