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

Filter Menu: Only allow Contains Option

5 Answers 1487 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 09 Oct 2014, 05:58 AM
I want to set the default filter option to contians or remove all other options. How can I accomplish this?


Code Snippet for Filter Configuration:
// TODO: set default filter operator to [contains]
    .Filterable(filter =>
    {
        filter.Extra(false);
        filter.Operators(op =>
        {
            op.ForString(str => str.Clear());
            op.ForString(str =>
            {
                str.Clear().Contains("Contains");
            });
        });
    })


Full Code:
@using NursingHomeStock.Resources
 
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = GlobalResources.Resident + "/" + GlobalResources.Residence;
}
 
<h2>@ViewBag.Title</h2>
 
@(Html.Kendo().Grid<NursingHomeStock.Models.ResidentViewModel>()
    .Name("AvailablePlaceTypesGrid")
    .Columns(columns =>
    {
        columns.Bound(rvm => rvm.FirstName);
        columns.Bound(rvm => rvm.LastName);
        columns.Bound(rvm => rvm.Sex)
            .ClientTemplate("#if (Sex == 1) { #" + GlobalResources.Male +
                "#} else if (Sex == 2) { #" + GlobalResources.Female +
                "# } #")
            .EditorTemplateName("DropDownListSex");
        columns.Bound(rvm => rvm.BirthDate).Format("{0:dd.MM.yyyy}").EditorTemplateName("Date");
        columns.Bound(rvm => rvm.SocialSecurityNumber);
        columns.Bound(rvm => rvm.Comment);
        columns.Command(command => command.Destroy().Text(GlobalResources.Delete));
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create().Text(GlobalResources.Create);
        toolbar.Save().CancelText(GlobalResources.Cancel).SaveText(GlobalResources.Save);
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(new []{ 5, 10, 20, 50, 100})
        .ButtonCount(5))
    // TODO: set default filter operator to [contains]
    .Filterable(filter =>
    {
        filter.Extra(false);
        filter.Operators(op =>
        {
            op.ForString(str => str.Clear());
            op.ForString(str =>
            {
                str.Clear().Contains("Contains");
            });
        });
    })
    .Navigatable() // Tabulator Support
    .Sortable()
    .ClientDetailTemplateId("ResidenceGrid")
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .Events(events => events
            .Error("App.errorHandler")
        )
        .Model(model =>
        {
            model.Id(e => e.Id);
            model.Field(e => e.Id).DefaultValue(Guid.NewGuid());
        })
        .Sort(sort => sort.Add("LastName").Ascending())
        .Read(read => read.Action("ReadResident", "Resident", new { ViewBag.nursingHomeId }))
        .Update(update => update.Action("UpdateResident", "Resident"))
        .Create(create => create.Action("CreateResident", "Resident", new { ViewBag.nursingHomeId }))
        .Destroy(destroy => destroy.Action("DestroyResident", "Resident"))
    )
    .Events(events => events.DataBound("App.Resident.dataBoundResidenceGrid"))
)
 
<script id="ResidenceGrid" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<NursingHomeStock.Models.ResidenceViewModel>()
          .Name("ResidenceGrid_ResidentId_#=Id#")
          .Columns(columns =>
          {
              columns.Bound(residence => residence.From).Format("{0:dd.MM.yyyy}").EditorTemplateName("Date");
              columns.Bound(residence => residence.To).Format("{0:dd.MM.yyyy}").EditorTemplateName("Date");
              columns.Bound(residence => residence.FirstUsage).Format("{0:dd.MM.yyyy}").EditorTemplateName("Date");
              columns.Bound(residence => residence.FileNumber);
              // columns.Bound(residence => residence.NursingHome).ClientTemplate("\\#=NursingHome.Name\\#");
              columns.Bound(residence => residence.PlaceType).ClientTemplate("\\#=PlaceType.Name\\#");
              columns.Bound(residence => residence.BedCategory)
                .ClientTemplate("\\# if (BedCategory == 1) { \\#" + GlobalResources.OneBed +
                    "\\# } else if (BedCategory == 2) { \\#" + GlobalResources.TwoBed +
                    "\\# } \\#")
                .EditorTemplateName("DropDownListBedCategory");
              columns.Command(command => command.Destroy().Text(GlobalResources.Delete));
          })
          .ToolBar(toolbar =>
          {
              toolbar.Create().Text(GlobalResources.Create);
              toolbar.Save().CancelText(GlobalResources.Cancel).SaveText(GlobalResources.Save);
          })
          .Editable(editable => editable.Mode(GridEditMode.InCell))
          //.Pageable(pageable => pageable.ButtonCount(5))
          .Navigatable()
          .Sortable()
          .DataSource(dataSource => dataSource
              .Ajax()
              .Batch(true)
              .Events(events => events
                  .Error("App.errorHandler")
              )
              .Model(model =>
              {
                  model.Id(residence => residence.Id);
                  model.Field(residence => residence.Id).DefaultValue(Guid.NewGuid());
                  // model.Field(residence => residence.FirstUsage).DefaultValue(DateTime.Now);
                  /*
                  model.Field(residence => residence.NursingHome).DefaultValue(
                      ViewData["defaultNursingHome"] as NursingHomeStock.Models.NursingHomeSmallViewModel
                      );
                  */
                  model.Field(residence => residence.PlaceType).DefaultValue(
                      ViewData["defaultPlaceType"] as NursingHomeStock.Models.PlaceTypeSmallViewModel
                      );
              })
              .Create(create => create.Action("CreateResidence", "Resident", new { residentId = "#=Id#", ViewBag.nursingHomeId }))
              .Read(read => read.Action("ReadResidence", "Resident", new { residentId = "#=Id#" }))
              .Update(update => update.Action("UpdateResidence", "Resident"))
              .Destroy(destroy => destroy.Action("DestroyResidence", "Resident"))
          )
          .ToClientTemplate()
    )
</script>
 
@section scripts
{
    <script type="text/javascript">
        //register custom validation rules
        (function ($, kendo) {
            $.extend(true, kendo.ui.validator, {
                rules: { // custom rules
                    socialsecuritynumbervalidation: function (input, params) {
                        //check for the rule attribute
                        if (input.is("[name='SocialSecurityNumber']") && input.val() != "") {
                            // TODO: Should realized as warning, should not block the save action
                            // return AustrianSocialSecurityNumber(input, "SocialSecurityNumber");
                            return true;
                        }
                        return true;
                    }
                },
                messages: { //custom rules messages
                    socialsecuritynumbervalidation: function (input) {
                        // return the message text
                        return input.attr("data-val-socialsecuritynumbervalidation");
                    }
                }
            });
        })(jQuery, kendo);
 
    </script>
}


5 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 09 Oct 2014, 08:15 AM
Hello Oliver,

Indeed the following code is correct
.Filterable(filter =>
{
    filter.Extra(false);
    filter.Operators(op =>
    {
        op.ForString(str =>
        {
            str.Clear().Contains("Contains");
        });
    });
})

Are you experiencing any issues with it on your end?

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Oliver
Top achievements
Rank 1
answered on 09 Oct 2014, 08:38 AM
Yes, the configuration of the filter has no effect to the filtermenu (only the extra param false setting produces the desired output).
0
Accepted
Dimiter Madjarov
Telerik team
answered on 09 Oct 2014, 10:01 AM
Hi Oliver,


There is an issue with the filter customization when the culture set in the web.config file is different than the default one. I think this is the case in the current scenario. As a workaround you should set the custom filters at a column level and leave empty the global Filterable() configuration.
E.g.
columns.Bound(client => client.ContactName).Filterable(filter =>
{
    filter.Extra(false);
    filter.Operators(op =>
    {
        op.ForString(str =>
        {
            str.Clear().Contains("Contains");
        });
    });
});

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Oliver
Top achievements
Rank 1
answered on 09 Oct 2014, 10:11 AM
Thanks, that solves the problem. Are there plans to implement this feature for the global filter configurations?

regards
0
Dimiter Madjarov
Telerik team
answered on 09 Oct 2014, 10:19 AM
Hello Oliver,


I am glad the issue is resolved. The fix for the global configuration is still under consideration from the development team, so I could not give a specific answer at the moment.

Have a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Oliver
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or