admin 管理员组文章数量: 1086019
I'm happy if I can get the filtering working client or serverside, but bining sending parameters on the DataSource action and ServerFiltering(true) results in an null filter value (text parameter).
The dropdownlist is part of a series which uses cascading.
View:
@(Html.Kendo().DropDownList()
.Name("name")
.OptionLabel(new SelectListItem { Text = "Select...", Value = "" })
.DataTextField("Text")
.DataValueField("Value")
.Filter("contains")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Action", "Controller")
.Data("params");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("parent")
)
<script>
function params() {
return {
a: '',
b: 1
};
}
</script>
Controller:
public JsonResult Action(string text, string a, int b)
{
return Json((List<SelectListItem>), JsonRequestBehavior.AllowGet);
}
"text" should contain the filter text.
I'm happy if I can get the filtering working client or serverside, but bining sending parameters on the DataSource action and ServerFiltering(true) results in an null filter value (text parameter).
The dropdownlist is part of a series which uses cascading.
View:
@(Html.Kendo().DropDownList()
.Name("name")
.OptionLabel(new SelectListItem { Text = "Select...", Value = "" })
.DataTextField("Text")
.DataValueField("Value")
.Filter("contains")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Action", "Controller")
.Data("params");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("parent")
)
<script>
function params() {
return {
a: '',
b: 1
};
}
</script>
Controller:
public JsonResult Action(string text, string a, int b)
{
return Json((List<SelectListItem>), JsonRequestBehavior.AllowGet);
}
"text" should contain the filter text.
https://demos.telerik./aspnet-mvc/dropdownlist/serverfiltering
Share Improve this question edited Apr 5, 2018 at 14:31 Chris asked Apr 5, 2018 at 14:18 ChrisChris 1701 silver badge13 bronze badges 2- Please elaborate your question. – Alexis Commented Apr 5, 2018 at 14:21
- The text parameter of the action is always null, should contain the filter text. Not sure how to elaborate that further. – Chris Commented Apr 5, 2018 at 14:28
2 Answers
Reset to default 5I think I understand what you are asking. You would like to send the current value of a drop down as a parameter to the data binding of a datasource read event function.
Try this-->
<script>
function params() {
return {
Text = $("#name").data("kendoDropDownList").text(),
a: '',
b: 1
};
}
</script>
Solution:
<script>
function params() {
return {
text = null,
a: '',
b: 1
};
}
var filter = $('#name').data('kendoDropDownList').dataSource.filter();
if (filter && filter.filters[0].operator == "contains") {
params.text = filter.filters[0].value;
}
</script>
The only way I could get it working as Kendo adds some default filters, so I had to use a conditional that looks for the filter type I'm using. If null it's not a search.
Given the example above, loading the 'params' javascript function like this before initializing should work. Both 'text', 'a' and 'b' will be available with their given values in the mvc Controller method every time the filter value is changing. This way you could pass in additinal parameters and values as required:
<script>
function params() {
var filterText = "";
var filter = $('#name').data('kendoDropDownList').dataSource.filter();
if (filter && filter.filters[0].operator == "contains") {
filterText = filter.filters[0].value;
}
return {
text: filterText,
a: '',
b: 1
};
}
</script>
@(Html.Kendo().DropDownList()
.Name("name")
.OptionLabel(new SelectListItem { Text = "Select...", Value = "" })
.DataTextField("Text")
.DataValueField("Value")
.Filter("contains")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Action", "Controller")
.Data("params");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("parent")
)
本文标签: javascriptKendo DropdownList server filtering with added parametersStack Overflow
版权声明:本文标题:javascript - Kendo DropdownList server filtering with added parameters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744025662a2520586.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论