Multiple values when using Server Filtering

2 posts, 0 answers
  1. Toby
    Toby avatar
    20 posts
    Member since:
    Nov 2010

    Posted 29 Jul Link to this post

    How do I filter when I have the option for multiple selections using the Separator property

    I have a Read action set up which passes the search data through to my controller and I have a client side script set up for the additional data

    When a user has selected one user and then starts typing for the second user this pass "Name One; Nam" to the controller.

    $("#distributionList").val() is passing the whole string and not the new search for the second name. How can I pass just the text that is being typed in and not the previously selected users.

     

    1.function onDistributionListAdditionalData(obj) {
    2.                return {
    3.                    text: $("#distributionList").val()
    4.                };
    5.            }

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    135 posts

    Posted 02 Aug Link to this post

    Hello Toby,

    You could split the string by the separator and get the last occurrence either on Client-side: 

    function onDistributionListAdditionalData(obj) {
        var autoComplete = $("#distributionList").data("kendoAutoComplete");
        var separator = autoComplete.options.separator;
        var value = autoComplete.value();
        var values = value.split(separator);
        if (values.length == 0) {
            return {
                text: value
            };
        }
        else {
            return {
                text: values[values.length - 1]
            };
        }
    }

    or Server-side:

    function onDistributionListAdditionalData(obj) {
        var autoComplete = $("#distributionList").data("kendoAutoComplete");
        var separator = autoComplete.options.separator;
        var value = autoComplete.value();
        var values = value.split(separator);
        if (values.length == 0) {
            return {
                text: value,
                separator: autoComplete.options.separator
            };
        }
        else {
            return {
                text: values[values.length - 1],
                separator: autoComplete.options.separator
            };
        }
    }

    public JsonResult GetProducts(string text, string separator)
    {  
        text = text.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries).Last();
        . . .
    }

    Regards,
    Peter Milchev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top