Grid Excel filter broken with DynamicDictionary and CustomAdaptor
Hi,
Getting System.InvalidCastException from DynamicObjectOperation.PerformFiltering from the Grid Excel filter when combined with DynamicDictionary and CustomAdaptor.
To Reproduce:
1) Filter on "ship country" by UK
2) Filter again on "ship country" again and a System.InvalidCastException is thrown before the filkter dialog is shown.
Regards,
Mike
@page "/datagrid-features"
@using System.Dynamic
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Data
@using System.Collections
<div class="col-lg-12 control-section">
<div class="content-wrapper">
<div class="row">
<SfGrid TValue="DynamicDictionary" DataSource="@Orders" AllowFiltering="true" AllowSorting="true" AllowGrouping="true" AllowPaging="true" Toolbar="@ToolbarItems"> <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true"></GridEditSettings>
<GridFilterSettings Type=Syncfusion.Blazor.Grids.FilterType.Excel></GridFilterSettings>
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridColumns>
<GridColumn Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" ValidationRules="@(new ValidationRules{ Required=true, Number=true})" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field="CustomerID" HeaderText="Customer Name" Width="120" ValidationRules="@(new ValidationRules { Required=true})"></GridColumn>
<GridColumn Field="Freight" HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" ValidationRules="@(new ValidationRules{ Required=true, Range = new double[]{1, 1000}})" Width="120"></GridColumn>
<GridColumn Field="OrderDate" HeaderText=" Order Date" ValidationRules="@(new ValidationRules{ Required=true})" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
<GridColumn Field="ShipCountry" HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150"></GridColumn>
<GridColumn Field="Verified" HeaderText="Active" DisplayAsCheckBox="true" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
</div>
@code {
private List<string> ToolbarItems = new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" };
public static List<DynamicDictionary> Orders = new List<DynamicDictionary>() { };
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select((x) =>
{
dynamic d = new DynamicDictionary();
d.OrderID = 1000 + x;
d.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)];
d.Freight = (new double[] { 2, 1, 4, 5, 3 })[new Random().Next(5)] * x;
d.OrderDate = (new DateTime[] { new DateTime(2010, 11, 5), new DateTime(2018, 10, 3), new DateTime(1995, 9, 9), new DateTime(2012, 8, 2), new DateTime(2015, 4, 11) })[new Random().Next(5)];
d.ShipCountry = (new string[] { "USA", "UK" })[new Random().Next(2)];
d.Verified = (new bool[] { true, false })[new Random().Next(2)];
return d;
}).Cast<DynamicDictionary>().ToList<DynamicDictionary>();
}
public class DynamicDictionary : System.Dynamic.DynamicObject
{
Dictionary<string, object> dictionary = new Dictionary<string, object>();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
string name = binder.Name;
return dictionary.TryGetValue(name, out result);
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
dictionary[binder.Name] = value;
return true;
}
//The GetDynamicMemberNames method of DynamicObject class must be overridden and return the property names to perform data operation and editing while using DynamicObject.
public override System.Collections.Generic.IEnumerable<string> GetDynamicMemberNames()
{
return this.dictionary?.Keys;
}
}
public class CustomAdaptor : DataAdaptor
{
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable DataSource = Orders;
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = DynamicObjectOperation.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
DataSource = DynamicObjectOperation.PerformSorting(DataSource.AsQueryable(), dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
DataSource = DynamicObjectOperation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<DynamicDictionary>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
}
SIGN IN To post a reply.
10 Replies
1 reply marked as answer
VN
Vignesh Natarajan
Syncfusion Team
October 15, 2020 10:12 AM UTC
Hi Michael,
Thanks for contacting Syncfusion support.
Query: “Getting System.InvalidCastException from DynamicObjectOperation.PerformFiltering from the Grid Excel filter when combined with DynamicDictionary and CustomAdaptor. ”
We are able to reproduce the reproduce the reported issue at our end while preparing a sample using your code example. We suggest you to resolve the issue by changing the order of actions in Read method of CustomAdaptor. We suggest you to perform the Sort operation at last before casting the datasource to get the total count.
Refer the below code example.
|
public class CustomAdaptor : DataAdaptor
{
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable DataSource = Orders;
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = DynamicObjectOperation.PerformSearching(DataSource, dm.Search);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
DataSource = DynamicObjectOperation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
DataSource = DynamicObjectOperation.PerformSorting(DataSource.AsQueryable(), dm.Sorted);
}
int count = DataSource.Cast<DynamicDictionary>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
|
.
And also from your code example, we found that you have used both CustomAdaptor and DataSource property to bind data to Grid. Kindly use any one method (either DataSource property / CustomAdaptor class) to bind data to Grid.
Please find the modified sample from below
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
MA
Michael Aston
October 15, 2020 11:58 AM UTC
Hi,
Restructuring the code as you suggested did fix it for this case but if you add search into the mix then it breaks again.
MA
Michael Aston
October 19, 2020 09:23 AM UTC
Hi,
Any news on this?
Regards,
Mike
MB
Maran Baskar
Syncfusion Team
October 22, 2020 02:59 PM UTC
Hi Michael,
Regards,
Maran Baskar
MB
Maran Baskar
Syncfusion Team
October 23, 2020 12:16 PM UTC
Hi Michael,
Greetings from Syncfusion.
We have validated the reported problem and we have confirmed it is a bug and logged the defect report for the same “Search in Excel Filter after GridSearch throws exception when using Custom Adaptor with Dynamic Dictionary”. Thank you for taking the time to report this issue and helping usimproveour product. Fix for the issue will be included in our weekly patch release which is expected to be rolled on or before end of November, 2020.
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.
Till then we appreciate your patience.
Regards,
Maran Baskar
MA
Michael Aston
December 11, 2020 10:05 AM UTC
This was scheduled for Vol3 but is still not fixed. Will it be in Vol4?
VN
Vignesh Natarajan
Syncfusion Team
December 14, 2020 10:49 AM UTC
Hi Michael,
Sorry for the inconvenience caused.
Due to unforeseen circumstances, we are unable to include the fix for the issue “Search in Excel Filter after GridSearch throws exception when using Custom Adaptor with Dynamic Dictionary” in our weekly patch release as promised. The fix for reported issue will be included in our weekly patch release which is expected to be rolled out by mid of January 2021.
Until then we appreciate your patience.
Regards,
Vignesh Natarajan
MA
Michael Aston
January 25, 2021 10:59 AM UTC
Can you tell me when this fix will be available?
VN
Vignesh Natarajan
Syncfusion Team
January 27, 2021 09:03 AM UTC
Hi Michael,
We regret for the inconvenience caused.
Due to unforeseen circumstances, we are unable to include the fix for the issue “Search in Excel Filter after GridSearch throws exception when using Custom Adaptor with Dynamic Dictionary” in our 2020 Volume 4 Service Pack release which is expected to be rolled out by end of this month. The fix for reported issue will be included in our weekly patch release which is expected to be rolled out by mid of February 2021.
Until then we appreciate your patience.
Regards,
Vignesh Natarajan
VN
Vignesh Natarajan
Syncfusion Team
April 8, 2021 10:58 AM UTC
Hi Michael,
We are glad to announce that our 2021 Volume 1 release (v19.1.0.54) has been rolled out successfully and in this release, we have included the fix for “Search in Excel Filter after GridSearch throws exception when using Custom Adaptor with Dynamic Dictionary” issue. So kindly update your NuGet (Syncfusion.Blazor) to our latest version (19.1.0.54 to resolve the reported issue)
Please find the Nuget package and release notes from below
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Vignesh Natarajan
Marked as answer
SIGN IN To post a reply.
- 10 Replies
- 3 Participants
- Marked answer
-
MA Michael Aston
- Oct 14, 2020 08:34 PM UTC
- Apr 8, 2021 10:58 AM UTC