Hi,
I have a Data Grid that displays a 'Group' which contains a nested Data Grid as a 'DetailTemplate' to display the 'Members' of each Group.
The 'Members' column in the 'DetailTemplate' displays each user's ID as an int.
I want to implement a Filter Template that displays a user's 'First Name' instead of their ID number. I know I have to use an 'ItemTemplate', but it is not working.
I have attached a video showing what end-product I want:
I want the 'Filter Template' to display each user's 'First Name' instead of their ID number just like how I have in my 'Edit Template'.
Thank you
Attachment: MultiSelect_ItemTemplate_88e4500d.zip
<SfGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true">
<GridFilterSettings Type="FilterType.Excel"></GridFilterSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.EmployeeID) HeaderText="ID" TextAlign="TextAlign.Center" Width="120">
<Template>
@{
var employee = (context as Order);
<span>@Employees.Where(x => x.EmployeeID == employee.EmployeeID).FirstOrDefault().FirstName</span>
}
</Template>
<FilterItemTemplate>
@{
var emp = (context as FilterItemTemplateContext);
<div>@Employees.Where(x => x.EmployeeID == (int?)Convert.ToInt32(emp.Value)).FirstOrDefault().FirstName</div>
}
</FilterItemTemplate>
</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> |
Hi Rahul,
Thanks for your help.
I want to display only the user names as the filter options if they are a member of that group. For example, if there are no members in a group, then there will be no filter options. And if there are only 2 members in a group (eg: Bob & Steve), then the filter options will only contain Bob & Steve.
Currently, the filter will display all users even if they are not a member of that Group. I have tried to filter out the members in my 'FilterItemTemplate' code, but it displays an empty filter option for non-members.
I have attached a video demonstration the issue and a picture of the code.
Thank you
Attachment: MultiSelect_ItemTemplate02_f96a0bd2.zip
Hello, my name is Cody. I am Kenny's Coworker and I will be overlooking this thread until he returns next week.
I have attached snippets of Code that I believe are related. From my understanding of the problem, and from the testing I have done, it appears that "FilterItemTemplate" will iterate through each possible member, and the code will output the correct <div> when the user is supposed to be in the group. However, when the <div> is not returned, the checkbox will instead render but be blank. Perhaps there is a way for FilterItemTemplate to skip members that are not in the group?
Apologies for my limited understanding of the problem, but I will do my best to see the problem through and provide the information you requested.
Hi Rahul,
I have attached a sample project that reproduces the issue. In the attachment, there is also a video showing the empty filter items.
For example, if I wanted to display filter items for Employee IDs greater than 45, the filter will display empty filter values for Employee IDs less than 45, and non-empty filter values for IDs greater than 45.
I want it so the empty values do not appear at all.
Thank you
Thank you for the update, Rahul.
[Index.razor]
@inject IJSRuntime Runtime
<SfGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true">
<GridEvents OnActionComplete="ActionCompletedHandler" TValue="Order"></GridEvents>
<GridFilterSettings Type="FilterType.Excel"></GridFilterSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.EmployeeID) HeaderText="ID" TextAlign="TextAlign.Center" Width="120">
<Template>
@{
var employee = (context as Order);
<span>@Employees.Where(x => x.EmployeeID == employee.EmployeeID).FirstOrDefault().FirstName</span>
}
</Template>
<FilterItemTemplate>
@{
var emp = (context as FilterItemTemplateContext);
if ((int?)Convert.ToInt32(emp.Value) > 45)
{
<div>@Employees.Where(x => x.EmployeeID == (int?)Convert.ToInt32(emp.Value)).FirstOrDefault().FirstName</div>
}
}
</FilterItemTemplate>
</GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
. . .
public async Task ActionCompletedHandler(ActionEventArgs<Order> args)
{
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.FilterAfterOpen) && args.ColumnName == "EmployeeID")
{
await Runtime.InvokeVoidAsync("hideCheckBox");
}
}
} |
[Interop.js]
function hideCheckBox() {
var chk = document.querySelectorAll(".e-ftrchk");
for (var i = 0; i < chk.length; i++) {
if (i != 0 && i < 46)
{
chk[i].style.display = "none";
}
}
}
|
[_Host.cshtml]
<head>
. . .
<link rel='nofollow' href="_content/Syncfusion.Blazor/styles/material.css" rel="stylesheet" />
<script src="~/Interop.js"></script>
</head> |
|
Hi Rahul,
This solution works fine for integer columns, but my current problem in within' my string column. I have modified the sample project to demonstrate the problem.
In the sample project, I am displaying only filter values that contain the string "Andrew". To do this, I attached a class of "empty-val" to filter values that do not contain "Andrew". I have also modified the interop function to extract the 'great grand parent' elements of the empty filter values and applied an attribute id to hide those elements.
Initially, the filter values populate correctly. However, if I use the filter search bar, the empty filter values will pop up again.
Please note that this is just a simple demonstration for the real problem that I am facing in my own project. In my project, I am querying members of a group, so I want to hide the non-members from the filter list. I have a similar problem as the attached sample project when I use the filter search bar. So please, do not give me a solution that uses the Interop call to check if the element contains the value "Andrew" as that will not help me.
EDIT:
I would like to add on my discovery:
It seems that when I search for the last item (of the filter list without using 'FilterItemTemplate') in the Filter list for the FilterItemTemplate, it is able to do so correctly.
My assumption is that the filter items are being popped off when using the filter search bar, and therefore the correct filter results contains elements with the class "empty-val" because it was previously applied to elements above it with empty filter values.
That is why searching for the last item will not show the problem because it is the last item of the stack and cannot be applied the "empty-val" class accidentally.
Thank you
Attachment: StringEmptyVal_e6be9eb0.zip
Hi,
Is there any update on this ticket?
Thank you
Hi Rahul,
When will this improvement feature be pushed out? I have a release for my project coming up that relies on this fix.
Thanks,
Kenney
Hi Rahul,
That is a long way to go as my project deadline is proposed the end of August. Is there any way possible to accel the solution to this ticket earlier?
Thank you for your cooperation,
Kenney
Hi Rahul,
I know you guys are working hard, and I appreciate the expedited accommodation. I am always trying to make Syncfusion better, so I am glad I'm able to help you with these innovative improvements.
Thank you,
Kenney
Hi Rahul,
Hope you guys are doing well over there at Syncfusion. I was wondering if you could give me an update on the release such as a definitive release date? I would like to be able to report to my upper management on the status of this ticket!
Thank you,
Kenney
Hi Rahul,
I know you guys are working hard and are busy, and I appreciate the work you are doing.
However, it is the end of the month, and I need to report a status update to my management.
I was curious to know if the upcoming path release is done?
Thank you,
Kenney
Hi Rahul,
I appreciate your honesty and apology. I know there are a lot bugs and work you guys are juggling around right now, so I understand the delay.
However, sometimes my managers may not understand the situation like how I do. It is because to them, they understood that an update was to be rolled out end of August as promised. But now, I have no excuses for them as it is now mid-September.
Our company has been using Syncfusion for some time now and I really enjoy the vast components you guys have developed. I want to keep supporting Syncfusion, but it will be difficult to give my managers a reason if there are delays like these. Therefore, in order for us to keep supporting Syncfusion, I hope you can roll out an update by mid-September as originally promised.
Thank you,
Kenney
Hi Jeevakanth,
Has the next patch been released yet?
Thank you,
Kenney
Hi Rahul,
Where is the internal source?
@using Syncfusion.Blazor.Grids
<SfGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="375">
<GridEvents OnActionBegin="ActionBegin" TValue="Order"></GridEvents>
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.CheckBox"></GridFilterSettings>
<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>
public void ActionBegin(ActionEventArgs<Order> args)
{
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.FilterBeforeOpen) && args.ColumnName.Equals("CustomerID"))
{
//You can set the customized datasource here
args.CheckboxListData = Orders.Take(5);
}
} |
Hi Rahul,
Thank you for getting back to me.
However, your solution does not work for columns of type integers. For example, if applied CheckboxListData to the column "OrderID", if you perform a search in the filter, the filter items will re-populate the original list of data and not the custom CheckboxListData. This method works fine for strings though.
I have attached the modified sample project and a video demonstrating the issue.
Attachment: CheckboxListData_for_Int_65306f49.zip
<SfGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="375">
<GridEvents OnActionBegin="ActionBegin" TValue="Order"></GridEvents>
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.CheckBox"></GridFilterSettings>
<GridColumns>
. ..
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
. ..
public void ActionBegin(ActionEventArgs<Order> args)
{
. . .
if (args.RequestType == Syncfusion.Blazor.Grids.Action.FilterSearchBegin)
{
if (string.Equals(FilterCol, "CustomerID", StringComparison.Ordinal))
{
.. .
}
if (string.Equals(FilterCol, "OrderID", StringComparison.Ordinal))
{
//pass the searchstring to custommethod and return the data
if(args.SearchString != "")
{
var lists = GetSearchedListOrd(args.SearchString);
//bind resultant list to CheckboxListData.
args.CheckboxListData = lists;
} else
{
args.CheckboxListData = Orders.Take(5);
}
}
}
}
. .
public List<Order> GetSearchedListOrd(string key)
{
//you need to handle the search and return the search result
var empdata = Orders.Take(5).Where(fil => fil.OrderID.ToString().StartsWith(key.ToLower()) || fil.OrderID.ToString().StartsWith(key.ToLower())).Select(x=>x.OrderID).ToList();
var data = new List<Order>();
foreach (var emp in empdata)
{
data.Add(Orders.Where(x => x.OrderID.Equals(emp)).FirstOrDefault());
}
//perform your custom action and return
return data;
}
}
|