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:
Full Code:
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
>
}