Display Count of Filtered Records in Containing SfTab

I have an SfTab that contains an SfGrid. In the SfTab HeaderTemplate I want to display a count of the filtered records in the Grid.

<SfTab>
<TabItems>
<TabItem>
<HeaderTemplate>
<div class="e-title">Active</div>
<div style="padding: 0 4px; margin-left: 2px; background-color: var(--button-primary); color: var(--button-primary-text)">@peopleCount</div>
</HeaderTemplate>
@* <ChildContent> *@
@* <TabHeader Text="Active"></TabHeader> *@
@* </ChildContent> *@
<ContentTemplate>
<div style="height: calc(100vh - 15rem);" class="grid-container">
<a name="target"></a>
<span class="error">@ErrorDetails</span>
<SfGrid TValue="Person" ID="StudentGrid" @ref="DefaultGrid" AllowPaging="true" AllowSorting="true" AllowExcelExport="true" AllowReordering="true"
ShowColumnMenu="true" ColumnMenuItems="@menuItems" ShowColumnChooser="true" RowHeight="70" Height="100%">
<SfDataManager Url="api/People" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
<GridEvents OnRecordDoubleClick="RecordDoubleClickHandler" TValue="Person" OnActionFailure="@ActionFalure"></GridEvents>
<GridPageSettings PageSize="50" PageSizes="new int[] {50, 100, 150, 200}"></GridPageSettings>
<GridEditSettings AllowAdding="true" AllowEditing="true" Mode="EditMode.Dialog">

When I try 

var a = DefaultGrid.GetFilteredRecords();
peopleCount = JsonConvert.DeserializeObject<List<Person>>(JsonConvert.SerializeObject(a)).Count();
as a Databound event, I get a circular reference error.

When I put the same code in the OnAfterRender for the component, @peopleCount is still 0.

Is there a way for me to display the number of Grid Filtered Records on the enclosing Tab Header?


1 Reply 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team February 15, 2021 08:40 AM UTC

Hi Judi, 

Greetings from Syncfusion support. 

We suggest you to call the GetFilteredRecords as async to overcome the reported problem. Please refer and use the codes below, 

 
public async Task DataBound(){    var a = await DefaultGrid.GetFilteredRecords();    peopleCount = JsonConvert.DeserializeObject<List<Order>>(JsonConvert.SerializeObject(a)).Count();}

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer
Loader.
Up arrow icon