Hi guys, I'm new to Kendo and am having problems getting the parameterMap to work. Please help me to understand why given the following datasource and grid configuration no model params are passed to the create controller action. I have read the documentation on parameterMap and still don't understand why my configuration is not working.
<
div
id
=
"grid"
style
=
"margin-bottom: 20px"
></
div
>
<!-- Data sources for supporter and supportee AutoComplete. -->
<
script
type
=
"text/javascript"
>
var supporterDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "<%= supporters_admin_customer_support_clients_url + '.json' %>",
dataType: "json"
},
schema: {
user_id: { type: 'number' },
full_name: { type: 'string' }
}
}
});
var supporteeDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "<%= supportees_admin_customer_support_clients_url + '.json' %>",
dataType: "json"
},
schema: {
user_id: { type: 'number' },
full_name: { type: 'string' }
}
}
});
</
script
>
<!-- Popup editor template for customer support client grid -->
<
script
id
=
"popup_editor"
type
=
"text/x-kendo-template"
>
<
div
class
=
"k-edit-label"
style
=
"padding-right: 10px"
>
<
label
for
=
"SupporterName"
>Customer Support Rep</
label
>
</
div
>
<
input
name
=
"SupporterName"
data-bind
=
"value:supporter_name"
data-value-field
=
"user_id"
data-text-field
=
"full_name"
data-source
=
"supporterDataSource"
data-role
=
"autocomplete"
/>
<
div
class
=
"clear"
></
div
>
<
div
class
=
"k-edit-label"
style
=
"padding-right: 10px"
>
<
label
for
=
"SupporteeName"
>Researcher</
label
>
</
div
>
<
input
name
=
"SupporteeName"
data-bind
=
"value:supportee_name"
data-value-field
=
"user_id"
data-text-field
=
"full_name"
data-source
=
"supporteeDataSource"
data-role
=
"autocomplete"
/>
</
script
>
<!-- Customer support client grid -->
<% content_for :javascript do %>
var crudServiceBaseUrl = "<%= admin_customer_support_clients_url %>",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + '.json',
dataType: "json"
},
create: {
url: crudServiceBaseUrl + '.json',
type: "POST",
dataType: "json"
},
update: {
url: function (data) {
return crudServiceBaseUrl + '/' + data.id + '.json';
},
type: "PUT",
dataType: "json"
},
destroy: {
url: function (data) {
return crudServiceBaseUrl + '/' + data.id + '.json';
},
type: "DELETE",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
pageSize: 20,
serverPaging: false,
serverFiltering: false,
serverSorting: false,
schema: {
model: {
id: "id",
fields: {
id: { editable: false, type: 'number' },
supporter_id: { type: 'number' },
supporter_name: { type: 'string' },
supportee_id: { type: 'number' },
supportee_name: { type: 'string' },
created_at: { editable: false, type: 'date' },
updated_at: { editable: false, type: 'date' }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
editable: {
mode: "popup",
template: kendo.template($("#popup_editor").html())
},
edit: function(e) {
$(e.container)
.find("input[name='SupporterName']")
.data("kendoAutoComplete")
.bind("change", function(e) {});
$(e.container)
.find("input[name='SupporteeName']")
.data("kendoAutoComplete")
.bind("change", function(e) {});
},
toolbar: ["create"],
height: 430,
filterable: true,
sortable: true,
pageable: true,
columns: [{
field: "supporter_name",
title: "Customer Support Rep",
type: "string"
}, {
field: "supportee_name",
title: "Researcher",
type: "string"
}, {
field: "created_at",
title: "Created At",
type: "date",
format: "{0:dd-MMM-yyyy hh:mm tt}",
parseFormats: ["yyyy-MM-dd'T'HH:mm:ss.zz"]
}, {
field: "updated_at",
title: "Updated At",
type: "date",
format: "{0:dd-MMM-yyyy hh:mm tt}",
parseFormats: ["yyyy-MM-dd'T'HH:mm:ss.zz"]
}, {
command: ["edit", "destroy"],
title: " ",
width: "175px"
}]
});
<% end %>