With Kendo UI, I am using an autocomplete box to try and retrieve data from my server. It is hitting an ASP.NET MVC controller with the following signature.
public ActionResult aspect(string term){
// ...
}
This means that the request needs to have the correct parameter in the url. Now the issue I am running into is that I cannot discover a way to specify this in the dataSource mechanics. I have read the documentation on parameterMap dozens of times and it makes absolutely no sense to me in any way.
This is complicated further by the fact that the page in question actually has 10-15 autocomplete text boxes at any one time, each dynamically created with dynamic identity.
The code I am using so far is as follows;
$(".autocomplete").kendoAutoComplete({
dataTextField: "Name",
dataSource: {
type: "json",
transport: {
read: {
url: "/search/aspect"
}
}
}
});
So is there anything I can do to tell it how to name the parameter it passes?
To make it more clear what I am trying to do, if I were doing this in jQuery, I would use ...
$.ajax({ url: '/search/aspects', data: { term: (insert the data here) } });
But because of the way all of this works, there is no set "selector" to get the autocomplete input, so I cannot retrieve its value from the input form element.
First, enable server-side filtering by setting this option:
Then the value is passed as one of the parameters into the
transport.parameterMap
function.If you were to log the object passed in to the parameterMap function like this:
then you would get an object that looks like this:
So you can use this to get the value entered into the AutoComplete box by doing:
Thanks for the clarification and help OnaBai. Here is the code that I got working after hours of frustration!
I'm a little confused as to what you're wanting to do. If you are just trying to pass the string term to the controller you can specify the data:
I think that there is a misunderstanding about the relation between
DataSource
andAutoComplete
.AutoComplete
has theinput
and uses aDataSource
for retrieving the data: theinput
does not belong to theAutoComplete
and as consequence you cannot get theinput
that is using aDataSource
from a method that is from theDataSource
(astransport.read.data
ortransport.parameterMap
).You need to unique identify which element has the input and the value that it contains.
What I do propose is getting the value using
document.activeElement.value
. Since you are typing it, the element that has the focus should be the element that you are using.The code would be:
Alternatively, you can enable
serverFiltering
and then Kendo UI links theinput
field with the filtering condition. The code would be: