How to combine two fields for Kendo UI autocomplete dataTextField?

I want to combine two fields for the Kendo autocomplete dataTextField property.

My datasouce has a FirstName field and a LastName field.

schema: { data: "d", model: { id: "PersonId", fields: { PersonId: { type: "number", editable: false // this field is not editable }, FirstName: { type: "text", validation: { // validation rules required: true // the field is required } }, LastName: { type: "text", validation: { // validation rules required: true // the field is required } } } } } 

Is there a way to configure autocomplete to display FirstName + LastName?

Maybe I need to do something with the data source, and if so, can someone provide a simple example?

Thanks!

+7
source share
2 answers

You should use template :

eg:

 template:"The name is : #= FirstName # #=LastName #" 
+8
source

Using templates is a valid solution. However, if you want your model to always have a composite or calculation field, you can define the analysis function in the definition of the scheme.

 schema: { data: "d", model: { id: "PersonId", fields: { PersonId: { type: "number", editable: false // this field is not editable }, FirstName: { type: "string", validation: { // validation rules required: true // the field is required } }, LastName: { type: "string", validation: { // validation rules required: true // the field is required } }, Name: { type: "string" // add any other requirements for your model here } } }, parse: function (response) { var values = response.d, n = values.length, i = 0, value; for (; i < n; i++) { value = values[i]; value.Name = kendo.format("{0} {1}", value.FirstName, value.LastName); } return response; } } 

The parsing function pre-processes the server response before using it, so you can modify existing fields or add new ones. Then you can refer to the field (s) directly in any controls that use the model.

+7
source

All Articles