MultiSelect as filter for grid using additionalData

1 posts, 0 answers
  1. Atlas
    Atlas avatar
    97 posts
    Member since:
    Jun 2009

    Posted 12 Jul 2013 Link to this post

    I just worked through adding a MultiSelect fillter on a page with a grid, and didn't see anything in the forums that addressed this issue, so I thought I would post the result that I came up with.
    <%= Html.Kendo().MultiSelectFor(m => m.FilterRoleIds)
            .Placeholder("Select Roles")
            .DataTextField("RoleName")
            .DataValueField("ApRoleId")
            .BindTo(ViewBag.ApRolesList)
    %>
      
    <%= Html.Kendo().MultiSelectFor(m => m.FilterCompanyIds)
            .Placeholder("Select Companies")
            .DataTextField("CompanyName")
            .DataValueField("CompanyId")
            .BindTo(ViewBag.CompanyList)
    %>
      
    <script language="javascript" type="text/javascript">
        function additionalData() {
            return {
                roleIds: "<%= ApRoleController.ReturnListValues(Model.FilterRoleIds) %>",
                companyIds: "<%= ApRoleController.ReturnListValues(Model.FilterCompanyIds) %>"
            };
        }
    </script>
     
            public static string ReturnListValues(List<string> list)
            {
                if (list == null || list.Count == 0) return "";
     
                string s = string.Empty;
     
                foreach (var item in list)
                {
                    if (s != string.Empty)
                        s += ",";
     
                    s += item;
                }
     
                return s;
            }
    Above is what I came up with.
    Telerik came up with the following:
    <script language="javascript" type="text/javascript">
        function additionalData() {
            var roleIds = <%= Html.Raw(Json.Encode(Model.FilterRoleIds)) %>;
            var data = {};
            for(var i=0; i< roleIds.length;i++){
                data["FilterRoleIds[" + i + "]"] = roleIds[i];
            }
            return data;
        }
    </script>
    Hopefully, this will be helpful to somebody.
Back to Top