I am trying to do this
http://demos.telerik.com/aspnet-mvc/dropdownlist/serverfiltering
It looks like I dont have to have any special action in the controler
This is my ddl
@(Html.Kendo().DropDownList()
.Name("commonCreditorID")
.DataTextField("CREDITOR_NAME")
.DataValueField("COMMON_CREDITOR_ID")
.HtmlAttributes(new { style = "width:250px" })
.Filter("contains")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("CommonCreditors_Read", "Home");
})
.ServerFiltering(true);
})
)
this is my action
public ActionResult CommonCreditors_Read()
{
GetLoggedUser("/");
EntitiesModel entities = new EntitiesModel();
var creditors = entities.TBL_COMMON_CREDITORS_LISTs
.Where(cc => !cc.OUT_OF_USE)
.OrderBy(o => o.CREDITOR_NAME)
.Select(cc => new { cc.CREDITOR_NAME, cc.COMMON_CREDITOR_ID });
return Json(creditors, JsonRequestBehavior.AllowGet);
}
it isnt filtering when I type..any ideas?
16 Answers, 1 is accepted
Hello Derek,
In the case of server filtering, the developer is responsible to filter the data on the backend. A string argument, containing the filter text will be received as a parameter for the action.
E.g.
public JsonResult GetProducts(string text)
{
...
var
products = northwind.Products.Select(product =>
new
ProductViewModel
{
...
});
if
(!string.IsNullOrEmpty(text))
{
products = products.Where(p => p.ProductName.Contains(text));
}
return
Json(products, JsonRequestBehavior.AllowGet);
}
Dimiter Madjarov
Telerik
I am using a cascading dropdown I need server filtering implemented on this one I tried the below read action it doesn't work.
public JsonResult GetMenus(int subCategoryId, string text)
{
var data = Uow.Repos.GetAllMenusBySubCategory(subCategoryId);
if (!string.IsNullOrEmpty(text))
{
text = text.ToLower();
data = data.Where(p => p.Name.ToLower().Contains(text));
}
var collection = data.Select(x => new
{
ID = x.ID,
Name = x.Name
});
return Json(collection, JsonRequestBehavior.AllowGet);
}
Can any one help me with this. I am not finding much on searching with a combination of these two functionalities.
Thanks
Hello Nithyanandam,
The provided sample code seems correct. If the problem is still perstisting, please send us small isolated runnable example that demonstrates it (here or in a support ticket), so we could inspect it locally.
Regards,Dimiter Madjarov
Telerik
Thanks for the reply Dimiter Madjarov.
I am not sure if I have given the correct picture of the situation so I am trying again Before I send the runnable example.
I am using this Kendo Dropdownlist In a Kendo Grid Editor Template.
Below Is the Dropdown and How I am sending Cascading Value to Read
@(Html.Kendo().DropDownListFor(m => m.MenuId)
.Name(
"MenuId"
)
.HtmlAttributes(
new
{ id =
"MenuId"
, style =
"width:95%;float:left;"
, @class =
"form-control"
})
.AutoBind(
false
)
.Filter(
"contains"
)
.OptionLabel(
"Select Menu Item..."
)
.DataTextField(
"Name"
)
.DataValueField(
"ID"
)
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action(
"GetMenus"
,
"Set"
).Data(
"filterMenus"
))
.ServerFiltering(
true
);
})
.CascadeFrom(
"ItemSubCategoryId"
)
)
function
filterMenus() {
return
{
subCategoryId: $(
"#ItemSubCategoryId"
).data(
"kendoDropDownList"
).value()
};
}
Here is My read
public
JsonResult GetMenus(
int
subCategoryId,
string
text)
{
var data = Uow.Repos.GetAllMenusBySubCategory(subCategoryId);
if
(!
string
.IsNullOrEmpty(text))
{
text = text.ToLower();
data = data.Where(p => p.Name.ToLower().Contains(text));
}
var collection = data.Select(x =>
new
{
ID = x.ID,
Name = x.Name
});
return
Json(collection, JsonRequestBehavior.AllowGet);
}
Is this issue caused because of the way I am sending the Data. Can I send Filter text in filterMenus javascript function is there any way I can access that over there.
Hello Nithyanandam,
Please open a support ticket, so we could discuss the case.
Regards,Dimiter Madjarov
Telerik
Hello Rachel,
Could you please send us an isolated runnable example that demonstrates the case, so we could have a look locally and provide assistance? I am looking forward to hearing from you.
Regards,Dimiter Madjarov
Telerik
I was not able to attach the whole project due to size restrictions. Please find as attachment the controller and View code which reproduces this problem. I am using
UI for ASP.NET MVC, v.2015.2.902
ASP.NET MVC 4
I reviewed the attached code and noticed that the child widget (QueryValue) overrides the Data callback in order to send the parent's value. Thus the default one that sends the "text" parameter is removed. You can find more details here: The solution of the issue is to send the widget's filter value along with the parent's value. To get the filter value, just access the filterInput field. You can check the Data callbacks of the CascadingComboBoxes demo, as it has enabled filtering unlike the DropDownList cascading demo.
Regards,
Georgi Krustev
Telerik
Hi Dimiter,
Could you please provide back-end side code in .net asmx web service.
i mean how to process filter settings in .net web service, but not using MVC.
Regards
Surinder
Hello Surinder,
We don't have such example that we could provide at the moment.
Regards,Dimiter Madjarov
Telerik by Progress
Hello Dimiter:
My filtering is still not working.
@(Html.Kendo().DropDownList()
.Name("experimentList")
.DataTextField("ExpName")
.DataValueField("ExperimentID")
.HtmlAttributes(new { style = "width:400px" })
.Filter(FilterType.Contains)
.Events(e => e.Change("onDDChangeExp"))
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetExperimentDropDownList", "Experiment");
})
.ServerFiltering(true);
})
)
The Action:
public JsonResult GetExperimentDropDownList(string filter)
{
ExperimentsComponent expComp = new ExperimentsComponent();
var exps = expComp.GetOrderedQueryable();
var list = exps.Select(e => new { e.ExperimentID, e.ExpName });
if (!String.IsNullOrEmpty(filter))
{
list = list.Where(e => e.ExpName.Contains(filter));
}
return Json(list, JsonRequestBehavior.AllowGet);
}
I've added the filter parameter but it is always null when the action gets called regardless of what I enter into the DDL. What am I missing?
Thank you.
Hello Giovanni,
The query string parameter of the request, containing the filter text is named text. Could you try renaming the parameter in your Action from filter to text and let me know if this fixes the issue?
Regards,Dimiter Madjarov
Telerik by Progress
Yes, thank you, Dimiter. That did the job!
Now an additional question. What do I do if I need an additional parameter in my filter Action? Say in my example above, if I need to add a Category parameter, for example:
public JsonResult GetExperimentDropDownList(string text, string category)
{
ExperimentsComponent expComp = new ExperimentsComponent();
var exps = expComp.GetOrderedQueryable();
var list = exps.Where(e => e.Category == category).Select(e => new { e.ExperimentID, e.ExpName });
if (!String.IsNullOrEmpty(text))
{
list = list.Where(e => e.ExpName.Contains(text));
}
return Json(list, JsonRequestBehavior.AllowGet);
}
Hello Giovanni,
You could use the following approach for sending additional metadata to the server. It could be accessed as additional parameters in the read action.
Regards,Dimiter Madjarov
Telerik by Progress