@page "/portal/lead/list"
@using Atlantis.Models
@using Atlantis.Interfaces
@using Syncfusion.Blazor.Data
@inject IUnitOfWork UnitOfWork
@inject NavigationManager NavigationManager
@inject IJSRuntime jsRuntime
@code {
public static ListLeadList { get; set; }
protected override void OnInitialized() {
LeadList = UnitOfWork.LeadRepo.Get(includeProperties: "InterestedProperty").ToList();
}
private async Task SelectLead(RecordDoubleClickEventArgsLeadInfo) {
await jsRuntime.InvokeAsync<object>("open", "/portal/lead/" + LeadInfo.RowData.Guid, "_blank");}
public class LeadDataAdaptor : DataAdaptor {
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null) {
IEnumerableDataSource = LeadList;
if (dm.Search != null && dm.Search.Count > 0) {
// Searching
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0) {
// Sorting
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) {
// Filtering
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast().Count();
if (dm.Skip != 0) {
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0) {
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
DataResult DataObject = new DataResult();
if (dm.Aggregates != null) // Aggregation
{
DataObject.Result = DataSource;
DataObject.Count = count;
DataObject.Aggregates = DataUtil.PerformAggregation(DataSource, dm.Aggregates);
return dm.RequiresCounts ? DataObject : (object)DataSource;
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
}
---------------------
Issue 1
When I tried searching, I get the following error - "Object reference not set to an instance of the object" at line "int count = DataSource.Cast
().Count()" stack trace -Document
Name | Value | Type | |
---|---|---|---|
StackTrace | " at System.Linq.Enumerable.WhereListIterator`1.MoveNext()\r at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)\r at Atlantis.Pages.Lead.List.LeadDataAdaptor.Read(DataManagerRequest dm, String key) in C:\\Workspace\\Atlantis\\Atlantis\\Pages\\Lead\\List.razor:line 64" | string |
Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type 'System.Collections.IEnumerable' to 'System.Collections.Generic.IEnumerable
Guidance 1
When the user applies filters, is there a way show the list of filtered columns and selected values?
Please guide me on these 3 points.
Hi,
Greetings from Syncfusion support.
Query: “Regarding Issue 1 and Issue 2”
Before proceeding further with your requirement. We need some more clarifications at your end. So kindly share below details to validate the issue further from our side.
The above provided details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible also Kindy get back to us if you need further assistance
Query: “When the user applies filters, is there a way show the list of filtered columns and selected values?”
We would like to inform that we have GetFilteredRecordsAsync and GetSelectedRecordsAsync method in DataGrid. We can use those method to get the detail of selected and filtered columns in DataGrid.
public async Task FilteredData() { var a = await Grid.GetFilteredRecordsAsync(); // To get filtered records var b = await Grid.GetSelectedRecordsAsync(); // To get selected records }
|
Reference:
Please let us know if you have any concerns.
Regards,
Monisha
@page "/portal/lead/list"
@using Atlantis.Data.Models
@using Atlantis.Data.Interfaces
@using Syncfusion.Blazor.Data
@using Atlantis.Services
@inject IUnitOfWork UnitOfWork
@inject NavigationManager NavigationManager
@inject IJSRuntime JsRuntime
<h3>List</h3>
<div class="row mb-2">
<div class="col">
<SfGrid TValue="Lead" AllowPaging="true" AllowSelection="true" AllowFiltering="true" ShowColumnChooser="true" EnableHover="true" AllowResizing="true" AllowMultiSorting="true" Toolbar="@(new List<string>() { "Search" })">
<SfDataManager AdaptorInstance="@typeof(LeadDataAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Single" Mode="Syncfusion.Blazor.Grids.SelectionMode.Row"></GridSelectionSettings>
<GridPageSettings PageSize="30"></GridPageSettings>
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel" ShowFilterBarStatus="true"></GridFilterSettings>
<GridEvents OnRecordDoubleClick="SelectLead" TValue="Lead"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Lead.Guid) HeaderText="Guid" Visible="false"></GridColumn>
<GridColumn Field=@nameof(Lead.Name) HeaderText="Name"></GridColumn>
<GridColumn Field=@nameof(Lead.Email) HeaderText="Email"></GridColumn>
<GridColumn Field=@nameof(Lead.Mobile) HeaderText="Mobile"></GridColumn>
<GridColumn Field=@nameof(Lead.InterestedProperty.Name) HeaderText="Project"></GridColumn>
<GridColumn Field=@nameof(Lead.InterestedUnit) HeaderText="Unit"></GridColumn>
<GridColumn Field=@nameof(Lead.InterestedBHK) HeaderText="BHK"></GridColumn>
<GridColumn Field=@nameof(Lead.Progress) HeaderText="Progress"></GridColumn>
<GridColumn Field=@nameof(Lead.AssignedTeam) HeaderText="Team"></GridColumn>
<GridColumn Field=@nameof(Lead.AssignedEmployee) HeaderText="Employee"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
@code {
public static List<Lead> LeadList { get; set; }
protected override void OnInitialized() {
LeadList = UnitOfWork.Leads.Get(IncludeProperties: "InterestedProperty").ToList<Lead>();
}
private async Task SelectLead(RecordDoubleClickEventArgs<Lead> LeadInfo) {
await JsRuntime.InvokeAsync<object>("open", "/portal/lead/" + LeadInfo.RowData.Guid, "_blank");
}
public class LeadDataAdaptor : DataAdaptor {
public override object Read(DataManagerRequest dm, string key = null) {
IEnumerable<Lead> DataSource = LeadList;
if (dm.Search != null && dm.Search.Count > 0) {
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0) {
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) {
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<Lead>().Count();
if (dm.Skip != 0) {
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0) {
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
DataResult DataObject = new DataResult();
if (dm.Aggregates != null) {
DataObject.Result = DataSource;
DataObject.Count = count;
DataObject.Aggregates = DataUtil.PerformAggregation(DataSource, dm.Aggregates);
return dm.RequiresCounts ? DataObject : (object)DataSource;
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
}
Hi,
Thanks for the information.
We have modified the shared code snippet at our end by providing the local Datasource. But we could not able to replicate the exact issue at our end. We suspect that the reported issue might be due to the delay in fetching the datasource or else kindly check whether the datasource has the corresponding search value. Kindly check the below attached sample and let us know whether you are facing the same issue in the below shared sample. Also kindly inform us whether we have done any mistakes in replicating the reported issue.
For the filtering query we would like to inform you that we can get the filter value in the argument of ActionBegin/ActionComplete event. Kindly check the below attached sample and code snippet for your reference.
<div class="row mb-2"> <div class="col"> <SfGrid TValue="Order" AllowPaging="true" AllowSelection="true" AllowFiltering="true" ShowColumnChooser="true" EnableHover="true" AllowResizing="true" AllowMultiSorting="true" Toolbar="@(new List<string>() { "Search" })"> <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> <GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Single" Mode="Syncfusion.Blazor.Grids.SelectionMode.Row"></GridSelectionSettings> <GridPageSettings PageSize="30"></GridPageSettings> <GridEvents OnActionBegin="ActionBegin" TValue="Order"></GridEvents> <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel" ShowFilterBarStatus="true"></GridFilterSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Width="150"></GridColumn>
</GridColumns> </SfGrid> </div> </div>
@code { public static List<Order> Orders { get; set; }
public void ActionBegin(ActionEventArgs<Order> args) { if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering) { // We can get the filter values in the argument } }
protected override void OnInitialized() { Orders = Enumerable.Range(1, 75).Select(x => new Order() { OrderID = 1000 + x, CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], Freight = 2.1 * x, }).ToList(); }
public class Order { public int OrderID { get; set; } public string CustomerID { get; set; } public double Freight { get; set; } }
public class CustomAdaptor : DataAdaptor { public override object Read(DataManagerRequest dm, string key = null) {
IEnumerable<Order> DataSource = Orders; if (dm.Search != null && dm.Search.Count > 0) { DataSource = DataOperations.PerformSearching(DataSource, dm.Search); }
if (dm.Sorted != null && dm.Sorted.Count > 0) { DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted); } if (dm.Where != null && dm.Where.Count > 0) { DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); } int count = DataSource.Cast<Order>().Count(); if (dm.Skip != 0) { DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); } if (dm.Take != 0) { DataSource = DataOperations.PerformTake(DataSource, dm.Take); } DataResult DataObject = new DataResult(); if (dm.Aggregates != null) { DataObject.Result = DataSource; DataObject.Count = count; DataObject.Aggregates = DataUtil.PerformAggregation(DataSource, dm.Aggregates);
return dm.RequiresCounts ? DataObject : (object)DataSource; } return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; } } } |
Please let us know if you have any concerns.
Regards,
Monisha
The issue with the searching still persists. This is my current OnInitialized function.
protected override void OnInitialized() {
LeadList = UnitOfWork.Leads.Get(IncludeProperties: "InterestedProperty").ToList<Atlantis.Data.Models.Lead>();
}
The data here is fetched from UnitOfWork. The function with GET function is mentioned below -
public virtual IEnumerable<TEntity> Get(
Expression<Func<TEntity, bool>> Filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> OrderBy = null,
string IncludeProperties = "") {
IQueryable<TEntity> query = _DbSet;
if (Filter != null) {
query = query.Where(Filter);
}
foreach (var includeProperty in IncludeProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) {
query = query.Include(includeProperty.Trim());
}
if (OrderBy != null) {
return OrderBy(query).ToList();
}
else {
return query.ToList();
}
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering)
{
// We can get the filter values in the argument
}
and var a = await Grid.GetFilteredRecordsAsync(); // To get filtered re
Yet I cannot get the key value pairs of the filtered columns and the respective values
Hi,
Thanks for the information.
We are facing difficulties in making sample as per you shared configuration. So we are unable to reproduce the reported issue at our end. If possible kindly share us an simple issue reproduceable sample. so that it would be very helpful for us to validate the issue further at our end.
Kindly get back to us if you have further queries.
Regards,
Monisha