Click here to Skip to main content
14,698,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A side note: Where does one post something just so people can google it in future?

So when trying to populate a field in a kendo grid using a custom editor with a kendo combobox or similar, the editor dorpdown works fine but as soon as you leave the editor (leave the field) it populates the input with [Object.object]. This is following the kendo example to the letter!

In this question I will post the code from the kendo page Configuration, methods and events of Kendo UI Grid[^]

What I have tried:

$("#grid").kendoGrid({
  columns: [ {
    field: "name",
    editor: function(container, options) {
     // create an input element
     var input = $("<input/>");
     // set its name to the field to which the column is bound ('name' in this case)
     input.attr("name", options.field);
     // append it to the container
     input.appendTo(container);
     // initialize a Kendo UI AutoComplete
     input.kendoAutoComplete({
       dataTextField: "name",
       dataSource: [
         { name: "Jane Doe" },
         { name: "John Doe" }
       ]
     });
    }
  } ],
  editable: true,
  dataSource: [ { name: "Jane Doe" }, { name: "John Doe" } ]
});
Posted
Updated 15-Feb-17 23:45pm

1 solution

The solution is to ignore that example and use the example they have for validation. Simply adding a couple of extra attributes solves the issue (I have no idea why)

editor: function (container, options) {
	// create an input element
	var input = $("<input required data_value_primitive = 'true' />");
	// set its name to the field to which the column is bound ('name' in this case)
	input.attr("name", options.field);
	// append it to the container
	input.appendTo(container);
	input.kendoComboBox({
		autoBind: false,
		suggest: true,
		dataSource: ["Sole Trader", "Partnership", "Ltd", "LLP", "Plc", "Charity", "Public Sector", "Club/Society"]
	});

}


I was my colleague who had this issue. He really didn't want to post anything because he's still pretty angry :Þ

If anyone has a better solution, or can explain this one then I'd really appreciate it.

As stated in the question. This post is just for posterity ^_^
   
Comments
Andy Lanng 16-Feb-17 5:05am
   
Oh, PS: I will accept this solution if none other is posted by the end of the day

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900