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

Cannot Pass "data" to the Kendo DataSource

1 Answer 336 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 2
Jason asked on 31 Mar 2017, 02:52 AM

I am trying to pass the value of the textbox into my datasource so I can pre-filter my AJAX result set. The following code always gives me an empty string for "issueid". The values I am passing for "token" and "rnd" work just fine. Debugging in the console for "$("#kAutoDuplicateId").val()" reveals the textbox value just fine as well.

<input id="kAutoDuplicateId" style="width: 500px;" />
<script type="text/javascript">
$(document).ready(function () {
    $("#kAutoDuplicateId").kendoAutoComplete({
        minLength: 1,
        dataTextField: "Id",
        template: 'Service Request ID: #: data.Id # - #: data.RequestType #',
        filter: "startswith",
        dataSource: {
            transport: {
                read: {
                    type: 'POST',
                    url: '/pages/ajax/searchreports.ashx',
                    dataType: "json",
                    data: {
                        issueid: $("#kAutoDuplicateId").val(),
                        token: $('#hdnCsrfToken').val(),
                        rnd: Math.random()
                    }
                }
            },
            pageSize: 5
        },
        placeholder: 'Enter the ID...'
    });
});
</script>

1 Answer, 1 is accepted

Sort by
0
Accepted
Nencho
Telerik team
answered on 03 Apr 2017, 11:27 AM
Hello Jason,

I would suggest you to use a function to return the parameters to the data object, hence, pass them to the method in your handler. This approach is described in our documentation article below:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read.data


Please consider the below implementation:

data: function () {
    var autoCompleteText = $("#kAutoDuplicateId").val();
    var hndFieldValue = $('#AutoCompleteValue').val();
    return {
        issueid: autoCompleteText,
        token: hndFieldValue,
        rnd: "1"
    };
 
}

Hope this would help.

Regards,
Nencho
Telerik by Progress
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 (charts) and form elements.
Tags
AutoComplete
Asked by
Jason
Top achievements
Rank 2
Answers by
Nencho
Telerik team
Share this question
or