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

AutoComplete Additional Data function parameters

2 Answers 1217 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 1
Roberto asked on 22 Sep 2017, 03:27 PM

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 Answers, 1 is accepted

Sort by
0
Roberto
Top achievements
Rank 1
answered on 22 Sep 2017, 03:53 PM

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
            };
        }

0
Dimitar
Telerik team
answered on 25 Sep 2017, 08:08 AM
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.
John
Top achievements
Rank 1
commented on 27 Sep 2021, 08:39 PM

There is a problem with using the .Data() function on the datasource. For example, let's say you want to include the value of another field on the same form as an additional filter value. Well, if the user has not yet selected or entered that value, there is no way to indicate that in the function. In other words, you cannot CANCEL or ABORT the read action if all of your data is not yet available.

The only thing you can really do is disable the autocomplete control until all of the other related data that you need has been entered.  This is a workable solution, but not necessarily an elegant solution.

Tags
AutoComplete
Asked by
Roberto
Top achievements
Rank 1
Answers by
Roberto
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or