We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Error when searching with customadaptor, Grouping shows empty data

@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 List LeadList { get; set; }


protected override void OnInitialized() {
LeadList = UnitOfWork.LeadRepo.Get(includeProperties: "InterestedProperty").ToList();
}


private async Task SelectLead(RecordDoubleClickEventArgs LeadInfo) {
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) {
IEnumerable DataSource = 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
NameValueType
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


Issue 2

The grouping does not work. I had tried the code from https://www.syncfusion.com/forums/156902/customadaptor-grouping-is-not-working. For which I get the error "

Severity Code Description Project File Line Suppression State

Error CS0266 Cannot implicitly convert type 'System.Collections.IEnumerable' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?) Atlantis C:\Workspace\Atlantis\Atlantis\Pages\Lead\List.razor 59 N/A"


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.


5 Replies

MS Monisha Saravanan Syncfusion Team May 8, 2023 11:32 AM UTC

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.


  • Share us the entire Grid code snippet.
  • Share us the Nuget version used at your end.
  • The grouping does not work. I had tried the code from https://www.syncfusion.com/forums/156902/customadaptor-grouping-is-not-working. For which I get the error " -> We have checked the sample and we could not able to replicate the reported issue
  • Kindly confirm us whether you have used expando/dynamic object at your end?
  • Share us the video demonstration of the issue.
  • If possible share us simple issue reproducing sample or try to reproduce the reported issue on the below attached sample. So that we will validate and we will check the reported issue in the provided sample.


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:

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_GetFilteredRecordsAsync

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_GetSelectedRecordsAsync


Please let us know if you have any concerns.


Regards,

Monisha



IW Imagine Works May 8, 2023 08:42 PM UTC

@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;
    }
  }
}


Grid code snippet is attached above.

Syncfusion.Blazor nuget version 21.2.3.

The data is being fetched and compiled to a List. Custom adaptor is used, mentioned in the code snippet above. Line for reference - LeadList = UnitOfWork.Leads.Get(IncludeProperties: "InterestedProperty").ToList<Lead>();


----

The line of codes shared for the filtered data -
I am more interested in the filters applied along with the values. Eg. The above snippet has column "BHK", "Unit". If filters are applied to these columns, I need to fetch the names of these


MS Monisha Saravanan Syncfusion Team May 9, 2023 07:50 AM UTC

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


Attachment: BlazorApp1_796d8b84.zip


IW Imagine Works May 9, 2023 09:05 PM UTC

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();
      }

    }

I have enabled the "AllowGrouping", yet even with the columns selected, the grid is empty.

As guided, I have tried using the event

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



MS Monisha Saravanan Syncfusion Team May 10, 2023 09:36 AM UTC

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



Loader.
Up arrow icon