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

kendo ui autocomplete - set data on load

4 Answers 1204 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Neelima
Top achievements
Rank 1
Neelima asked on 11 Nov 2017, 01:04 AM

I have a textbox for which I added kendoAutoComplete function. This is working fine. However, I wanted to set some value to this textbox upon the page load (I get the value from DB). With KendoAutoComplete, I am unable to set this.
I can either implement KendoAutoComplete or set datsource. Both of them work fine separately. Where as, if I include the code related to both - it doesnt work. Below is the code. Can you please throw me some inputs if you have come across this issue?

 

myController.js

$("#txtPartNumbers").kendoAutoComplete({
            dataSource: {
                serverFiltering: true,
                enforceMinLength: true,
                transport: {
                    read: {
                        url: ApiBaseUrl.val + 'inventoryLocation/getParts',
                        type: "get",
                        dataType: "json",
                        data: function () {
                            return { partNumber: $scope.autoCompleteText }
                        }
                    }
                },
            },
            change: function(e) {
                $scope.autoCompleteText = this.value();
            },
            filter: "startswith",
            //placeholder: "Select Inventory Parts..",
            minLength: 3,
            separator: ", "
        });

 

cshtml:

<input id="txtPartNumbers" type="text" ng-model="filterByPartNumbers" class="form-control filterTextArea" style="width: 300px;height:80px;" placeholder="Enter Part Numbers (Comma sepatared)" />

I am setting "filterByPartNumbers" value in my controller

....

var data = getDataFromDB();

$scope.filterByPartNumbers = data.partNumbers;

...

Appreciate you help.

 

Thank you!!

 

 

 

4 Answers, 1 is accepted

Sort by
0
Neelima
Top achievements
Rank 1
answered on 13 Nov 2017, 07:02 PM

I was able to set the value as below:

    $("#txtPartNumbers").data("kendoAutoComplete").value(data.partNumbers);

You can mark this as closed now.

Thanks!

0
Neelima
Top achievements
Rank 1
answered on 30 Nov 2017, 01:15 AM

Sorry to come back to this. I used jQuery above to access the control in my controller.

Can this be done in angular please?

something like..

Instead of $("#txtPartNumbers").kendoAutoComplete({....

$scope.filterByPartNumbers = {...

I need to avoid jQuery and access the control directly in Angularjs. 

 

Appreciate your help.

 

Thanks!

0
Ivan Danchev
Telerik team
answered on 01 Dec 2017, 04:13 PM
Hi Neelima,

If you declare the AutoComplete like this:
<input kendo-auto-complete="txtPartNumbers"

You would be able to get a reference to it and call its value method as shown below:
$scope.txtPartNumbers.value();

Dojo example.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Neelima
Top achievements
Rank 1
answered on 01 Dec 2017, 06:24 PM

Many thanks Ivan!!

 

Appreciate your help on this.

 

Regards

Neelima

Tags
AutoComplete
Asked by
Neelima
Top achievements
Rank 1
Answers by
Neelima
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or