This is a migrated thread and some comments may be shown as answers.

MultiSelect as filter for grid using additionalData

0 Answers 66 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Atlas
Top achievements
Rank 1
Atlas asked on 12 Jul 2013, 05:16 PM
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.

No answers yet. Maybe you can help?

Tags
MultiSelect
Asked by
Atlas
Top achievements
Rank 1
Share this question
or