最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Kendo DropdownList server filtering with added parameters - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

I 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")
)
发布评论

评论列表(0)

  1. 暂无评论