This is a migrated thread and some comments may be shown as answers.

Complex Filter

1 Answer 67 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Joel asked on 29 Oct 2020, 04:41 PM

I have a Session object.  Each Session can be related to many Templates and each template has a list of Items (like an Enum list).  Users can define a Template and its List of enums.  The fun is that the user needs to filter on these dynamic properties and I'm trying to figure out how to do it.  I need your help.

Template 1

- List Item 1

- List Item 2

- List Item 3

In the field list I need the list of Templates... which is dynamic.  Right now, I have "Name".  I need "Template 1", "Template 2", etc.  Then, I need a pick list for each of them based on their own Items.  So, select template 1 and filter on List Item 1.  Give me all the sessions where Template 1's value is List Item 1.  How do I do this in your Filter control.

Also, a side note.  There is NO documentation on how to define the Html.Kendo().DataSource object.  I don't believe my example works.  I actually have the values in the MODEL and would like to just use the given values without needing to perform an Action.

 

View:

@(Html.Kendo().DataSource<SessionOptionTemplate> ()
    .Name("templateDataSource")
    .Ajax(d => d.Read(
        r => r.Action("Templates", "Sessions"))))
     
@(Html.Kendo().Filter<SessionOptionTemplate>()
    .Name("filter")
    .MainLogic(FilterCompositionLogicalOperator.Or)
    .ApplyButton()
    .ExpressionPreview()
    .Fields(f =>
    {
        f.Add(p => p.Name).Label("Name");
    })
    .DataSource("templateDataSource"))

Controller:

public async Task<IActionResult> Templates(
    [DataSourceRequest] DataSourceRequest request)
{
    var dsResult = await profileService.SessionOptionTemplates.ToDataSourceResultAsync(request);
    return Json(dsResult);
}

 

Template:

public partial class SessionOptionTemplate
{
    public int Id { get; set; }
 
    [MaxLength(50)]
    public string Name { get; set; }
    [MaxLength(128)]
    public string Description { get; set; }
 
    public int Order { get; set; }
 
    public DateTime AddTimestamp { get; set; } = DateTime.UtcNow;
    public DateTime? DeactivateTimestamp { get; set; }
 
    public ICollection<SessionOptionItem> SessionOptionItems { get; set; } = new HashSet<SessionOptionItem>();
}

 

Items:

public partial class SessionOptionItem
{
    [Key]
    public int Id { get; set; }
    public int SessionOptionTemplateId { get; set; }
 
    [MaxLength(50)]
    public string Name { get; set; }
    [MaxLength(128)]
    public string Description { get; set; }
 
    public DateTime AddTimestamp { get; set; } = DateTime.UtcNow;
    public DateTime? DeactivateTimestamp { get; set; }
}

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 Nov 2020, 02:25 PM

Hi Joel,

 

You can achieve this requirement using the .Custom Operator approach:

 .Custom("oddNumbers", c=> c.Text("Odd numbers").Handler("oddNumbersHandler")))
As demonstrated here:
https://demos.telerik.com/aspnet-core/filter/operators

And inside the script function, you could use your own condition to achieve the Template filtering:

    function oddNumbersHandler(item) {
        return item % 2 === 1;
    }
And the Documentation of the DataSource Helper is located here:
https://docs.telerik.com/aspnet-core/html-helpers/datasource/overview 

I hope this will prove helpful.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Filter
Asked by
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Eyup
Telerik team
Share this question
or