AutoComplete Additional Data function parameters

3 posts, 0 answers
  1. Roberto
    Roberto avatar
    2 posts
    Member since:
    Sep 2015

    Posted 22 Sep Link to this post

    Hello,

    Hello, I have to pass a string parameter (in particular the field name) to the function of the additional parameters. One such thing, see autocompleteAdditionalData:

    @(Html.Kendo().AutoComplete()
                                .Name("L1CFOR")
                                .HtmlAttributes(new { @class = "form-control mb-2 mr-sm-2 mb-sm-0", placeholder = "L1CFOR", style = "max-width: 120px;" })
                                .MinLength(3)
                                .DataTextField("WKCELE")
                                .Filter("contains")
                                .Template("<span>${data.WKXTAB} ${data.WKCELE} ${data.WKDESE}</span>")
                                .AutoWidth(true)
                                .DataSource(source =>
                                 {
                                     source.Read(read =>
                                     {
                                         read.Action("AutoComplete", "Zoom")
                                            .Data("autocompleteAdditionalData('L1CFOR')");
                                     })
                                    .ServerFiltering(true);
                                 })
                                .Events(e =>
                                    {
                                        e.Select("autocompleteSelect");
                                    })
                            )

     

    How can I do. thank you.

    Best regards.

     

    M

  2. Roberto
    Roberto avatar
    2 posts
    Member since:
    Sep 2015

    Posted 22 Sep in reply to Roberto Link to this post

    This is my solution 

    read.Action("AutoComplete", "Zoom", new { fieldName= "L1CFOR"})

     

    and

     

            function autocompleteAdditionalData(e) {
                var val = e.filter.filters[0].value;
                return {
                    fieldValue: val
                };
            }

  3. Dimitar
    Admin
    Dimitar avatar
    218 posts

    Posted 25 Sep Link to this post

    Hello Roberto,

    I am attaching an ASP.NET MVC solution, where a similar scenario to the one described is demonstrated (Kendo UI Autocomplete passing additional parameter on read data request).

    To achieve the desired behavior, I have used the Data() method, which specified the JavaScript function that will be used to pass additional parameters to the remote service:
    @(Html.Kendo().AutoComplete()
    ...
    .DataSource(source =>
    {
    source.Read(read =>
    {
    read.Action("GetAutoCompleteData", "Home")
    .Data("autocompleteAdditionalData");
    })
    })
    )

    The function needs to be defined as follows:
    <script>
    function autocompleteAdditionalData(e) {
    return {
    filterText: e.filter.filters[0].value,
    fieldName: "L1CFOR"
    }
    }
    </script>

    Then, the filterText and fieldName will be successfully received in the controller action method:
    public ActionResult GetAutoCompleteData(string filterText, string fieldName)
    {
    }


    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top