Simple Kendo auto complete

by grippstick

HTML

<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.metro.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"></script>
<input id='autoComplete'/>

JavaScript

var data = [{
    ID: 1,
    Name: 'Frank Harris'},
{
    ID: 2,
    Name: 'Ted Harris'},
{
    ID: 3,
    Name: 'Chuck Norris'}];



$("#autoComplete").kendoAutoComplete({
    dataTextField: "Name",
    dataValueField: "ID",
    minLength: 1,
    dataSource: new kendo.data.DataSource({
        serverFiltering: true,
        transport: {
            read: {
                url: "/echo/json/",
                //using jsfiddle echo service to simulate JSON endpoint
                dataType: "json",
                type: "POST",
                data: {
                    // /echo/json/ echoes the JSON which you pass as an argument
                    //we use the d, because that is how WCF returns it
                    json: JSON.stringify({
                        d: data
                    })
                }
            },
            parameterMap: function(options,operation){
                //this is where we transform the options into somethig that matches our 
                //service signature
                if(operation==='read'){
                    //example
                    //return kendo.stringify({PersonName:'options.filter.filters[0].value'});
                }
                
                return options;
            }
        },
        schema: {
            data: "d"
        }
    }),
    placeholder: "Search by Person..."
});