I'm setting up a MultiSelect as shown below.
How can setup sorting of the DataSource?
@(Html.Kendo().MultiSelect()
.Name("Country")
.DataTextField("Country")
.DataValueField("CountryId")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCountries", "Helper").Data("{ any: false }");
});
})
)
4 Answers, 1 is accepted
In order to configure the Sort() rule for the MultiSelect DataSource, you will have to use its Custom() option:
@(Html.Kendo().MultiSelect() .Name("Country") .DataTextField("Country") .DataValueField("CountryId") .Filter(FilterType.Contains) .DataSource(source => source .Custom() .Transport(t => t .Read(r => r .Action("GetCountries", "Home") .Data("{ any: false }") ) ) .Sort(s => s .Add("Country") .Descending() ) ))and:
public ActionResult GetCountries(){ var result = new object[] { new { CountryId = 1, Country = "Bulgaria" }, new { CountryId = 2, Country = "France" }, new { CountryId = 3, Country = "Uganda" } }; return Json(result, JsonRequestBehavior.AllowGet);}I hope that the above helps you. Should you have any other questions, please do not hesitate to contact us.
Regards,
Veselin Tsvetanov
Progress Telerik
Thanks Veselin,
only if I setup the .DataSource this way can I make it work:
.DataSource(source => source
.Custom()
.Sort(s => s.Add("CountryName"))
.Transport(t => t
.Read(read =>
{
read.Action("GetCountries", "Helper");
})
)
)
And I can make the sending of the parameter data (.Data("{ any: false }")) work.
Could you try to add bool any as parameter to the GetCountries method and show how to pass the parameter?
public ActionResult GetCountries(bool any)
{
var result = new object[]
{
new { CountryId = 1, Country = "Bulgaria" },
new { CountryId = 2, Country = "France" },
new { CountryId = 3, Country = "Uganda" }
};
return Json(result, JsonRequestBehavior.AllowGet);
}
Thanks
/Morten
Attached you will find a simple MVC project implementing the discussed scenario. The GetCountries() controller action accepts a parameter of type bool with name any:
public ActionResult GetCountries(bool any){ var result = new object[] { new { CountryId = 1, Country = "Bulgaria" }, new { CountryId = 2, Country = "France" }, new { CountryId = 3, Country = "Uganda" } }; return Json(result, JsonRequestBehavior.AllowGet);}It also properly returns the sorted data to the widget.
Regards,
Veselin Tsvetanov
Progress Telerik
