Im having trouble with the combobox as a custom editor. Populating the values are fine, however when selected the entire object (from the combobox) of the row is put into the bound field. This displays itself as [object Object]
Ive copied the column from the demo http://demos.kendoui.com/web/grid/editing-custom.html as is acting the same strange way that my own field does.
[update solving problems while going along]
Ive had similar problems before but just changed how it was populated. This works fine:
This is the one I need working:
The editor of the cueCollection is:
but it currently has two problems. Clicking on any item it will select correctly and display correctly (in edit row) until finishing with row and clicking update. The first time this it is done the row will display "[object Object]" with the save method showing me the values of the model:
other fields are excluded as they are just general columns and are working as expected. Im expecting the category to be populated as "Dairy Products" and cueCollection to be "4".
These are the columns:
Schema
changing the field type of "Category" to a string seemed to have fixed its return value from the edit row. cueCollection was not so lucky.
the ajax response for the dropdown list is nothing too special:
Overall my aim would be to add the entire json object into the column:
as it would be easier to navigate and understand in its future context. Seeing that this is what it is giving me lets roll with it, although im expecting just the id field.
Back on track:
lets skip trying to get just the id, as the object looks far more exciting.
datasource - schema - model - cueCollection
lets give it a default so that creating a new row doesnt break so easily.
combobox data result
selecting the first item and clicking on the update row it will appear as undefined (one of the problems i had earlier but hadnt really noted).
selecting the second will populate cueCollection as expected (as observed). Clicking update will set the field as [object][object] so lets add a client template.
how the column looks in the grid definition:
current problems:
selecting the first item doesn't work. Lets try adding the option label to see if it is just that first field.
... *scratches head* ... selecting any item is causing problems now. As it has now decided on binding the "Id" value and now losing the object. This is turning into one of those get what you want at the wrong time scenarios.
Interesting. Adding in the option-label fixed the data bind issue, but broke how I was now expecting it. So now I need the data row value instead of a data field value.
Ok now quite confused. It is now selecting the object again.
Ive changed the editor to:
however the action of the dropdown has gone back to selecting the object over the Id
Can anyone describe what is going on with the dropdown. Static datasources seem to bind perfectly well, but ajax based data sources seem to be giving me the run around. It seems a little random now when it wants to select the Id or select the Object.
Any insight would be wonderful as I've spent far too long trying to get the dropdown to act consistently.
Thanks,
Matt
Ive copied the column from the demo http://demos.kendoui.com/web/grid/editing-custom.html as is acting the same strange way that my own field does.
[update solving problems while going along]
Ive had similar problems before but just changed how it was populated. This works fine:
var
proxyDropDownEditor =
function
(container, options){
var
data = [
{ text:
"none"
},
{ text:
"HTTP"
},
{ text:
"CONNECT"
},
{ text:
"best"
}
];
$(
'<input data-bind="value:'
+ options.field +
'"/>'
)
.appendTo(container)
.kendoDropDownList({
dataTextField:
"text"
,
dataValueField:
"text"
,
dataSource: data
});
};
This is the one I need working:
The editor of the cueCollection is:
function
cueCollectionEditor(container, options){
var
dataSource =
new
kendo.data.DataSource({
type:
"json"
,
transport: {
read:
"/OrchardLocal/Nyx/EditCueCollection/List?ContentId=29"
},
schema: {
model: {
id:
"Id"
}
}
});
$(
'<input data-text-field="Name" data-value-field="Id" data-bind="value:'
+ options.field +
'"/>'
)
.appendTo(container)
.kendoDropDownList({
autoBind:
false
,
dataSource: dataSource
});
//$('<input name="' + options.field + '"/>')
// .appendTo(container)
// .kendoDropDownList({
// autoBind: false,
// dataTextField: "id",
// dataValueField: "id",
// dataSource: options
//});
}
but it currently has two problems. Clicking on any item it will select correctly and display correctly (in edit row) until finishing with row and clicking update. The first time this it is done the row will display "[object Object]" with the save method showing me the values of the model:
Category
Object { __metadata={...}, CategoryID=4, CategoryName=
"Dairy Products"
, more...}
cueCollection
Object { Id=4, Name=
"Carousel 2"
}
dirty:
false
proxyType:
"best"
These are the columns:
{ field:
"cueCollection"
, title:
"Cues"
, editor: cueCollectionEditor
//template: kendo.template($("#cueCollectionColumnTemplate").html())
},
{ field:
"Category"
, width:
"150px"
, editor: categoryDropDownEditor },
{ field:
"proxyType"
, title:
"Proxy Type"
, editor: proxyDropDownEditor },
{ command: [
"edit"
,
"destroy"
], title:
" "
, width:
"210px"
}
Schema
schema: {
model: {
id:
"title"
,
fields: {
title: { type :
"string"
, nullable:
false
},
proxyType: { type:
"string"
, defaultValue:
"best"
},
position : { type:
"number"
, defaultValue: 0 },
cueCollection: { type:
"number"
},//changing the type to number removed the viewmodel from being returned
Category: { type:
"string"
}
//changing the type to string fixed it from being a object returned to the correct value
}
}
}
the ajax response for the dropdown list is nothing too special:
[{
"Id"
:2,
"Name"
:
"collection1"
},{
"Id"
:4,
"Name"
:
"collection
2"
}]
Overall my aim would be to add the entire json object into the column:
{
"Id"
:2,
"Name"
:
"collection1"
}
as it would be easier to navigate and understand in its future context. Seeing that this is what it is giving me lets roll with it, although im expecting just the id field.
Back on track:
lets skip trying to get just the id, as the object looks far more exciting.
datasource - schema - model - cueCollection
lets give it a default so that creating a new row doesnt break so easily.
cueCollection: { defaultValue: { Id:0, Name:
""
} },
[{
"Id"
:2,
"Name"
:
"collection1"
},{
"Id"
:4,
"Name"
:
"collection
2"
}]
selecting the first item and clicking on the update row it will appear as undefined (one of the problems i had earlier but hadnt really noted).
selecting the second will populate cueCollection as expected (as observed). Clicking update will set the field as [object][object] so lets add a client template.
...
function
templateCollection(mModel){
if
(!mModel)
return
"none selected"
;
return
mModel.Name;
}
</script>
<script id=
"cueCollectionColumnTemplate"
type=
"text/x-kendo-tmpl"
>
#: templateCollection(cueCollection) #
</script>
{ field:
"cueCollection"
, title:
"Cues"
,
editor: cueCollectionEditor,
template: kendo.template($(
"#cueCollectionColumnTemplate"
).html())
},
current problems:
selecting the first item doesn't work. Lets try adding the option label to see if it is just that first field.
$(
'<input data-bind="value:'
+ options.field +
'"/>'
)
.appendTo(container)
.kendoDropDownList({
dataTextField:
"Name"
,
dataValueField:
"Id"
,
autoBind:
false
,
dataSource: dataSource,
optionLabel:
"Select..."
});
Interesting. Adding in the option-label fixed the data bind issue, but broke how I was now expecting it. So now I need the data row value instead of a data field value.
Ok now quite confused. It is now selecting the object again.
Ive changed the editor to:
var
hiddenBox = $(
'<input type="hidden" data-bind="value:'
+ options.field +
'"/>'
).appendTo(container);
var
box = $(
'<input data-bind="value:'
+ options.field +
'"/>'
)
.appendTo(container);
var
kendoDropDown = box.kendoDropDownList({
dataTextField:
"Name"
,
dataValueField:
"Id"
,
autoBind:
false
,
dataSource: dataSource,
optionLabel:
"Select..."
});
however the action of the dropdown has gone back to selecting the object over the Id
Can anyone describe what is going on with the dropdown. Static datasources seem to bind perfectly well, but ajax based data sources seem to be giving me the run around. It seems a little random now when it wants to select the Id or select the Object.
Any insight would be wonderful as I've spent far too long trying to get the dropdown to act consistently.
Thanks,
Matt