Hey guys,
I have a grid bound to a DataSource which references local data. The data is loaded with a prior ajax call and is simply re-used in this DataSource to save on a round trip to the server. The local data is a subset of a larger data set.
I have a need to perform CRUD operations on this local data via a grid. Prior to sending the payload to the server, I need to map the model to a server-friendly object graph. I assume the best way to do this is via the transport.parameterMap option.
Here's my grid & DataSource configuration:
For completeness sake, here is my prime.dsCrud function:
I realize I could probably do this in the prime.dsCrud function's "data" configuration, but I would prefer to leave this function more generic. Can anyone explain to me why my transport.parameterMap isn't firing?
Thanks!
I have a grid bound to a DataSource which references local data. The data is loaded with a prior ajax call and is simply re-used in this DataSource to save on a round trip to the server. The local data is a subset of a larger data set.
I have a need to perform CRUD operations on this local data via a grid. Prior to sending the payload to the server, I need to map the model to a server-friendly object graph. I assume the best way to do this is via the transport.parameterMap option.
Here's my grid & DataSource configuration:
grid.kendoGrid({
dataSource: {
transport: {
read:
function
(options) {
options.success(filters);
// filters is the local array of data
},
create:
function
(options) {
prime.dsCrud({ url:
'CreateFilters'
, crud: options });
},
update:
function
(options) {
prime.dsCrud({ url:
'UpdateFilters'
, crud: options });
},
destroy:
function
(options) {
prime.dsCrud({ url:
'DestroyFilters'
, crud: options });
},
parameterMap:
function
(options, operation) {
console.log(operation);
// *** never fires! ***
}
},
batch:
true
,
pageSize: 10,
schema: {
model: {
id:
'id'
,
fields: {
id: { editable:
false
, nullable:
true
},
member: { type:
'string'
, validation: { required:
true
} },
operator: { type:
'number'
, validation: { required:
true
} },
dataType: { type:
'string'
, validation: { required:
true
} },
value: { type:
'string'
, validation: { required:
true
} }
}
}
}
},
sortable:
true
,
pageable:
true
,
filterable:
false
,
editable:
true
,
navigatable:
true
,
toolbar: [
"create"
,
"save"
,
"cancel"
],
columns: [
{
field:
'member'
,
title:
'Column'
},
{
field:
'operator'
,
title:
'Operator'
},
{
field:
'value'
,
title:
'Value(s)'
},
{
command:
'destroy'
,
title:
''
,
width:
'170px'
}
]
});
For completeness sake, here is my prime.dsCrud function:
prime.dsCrud =
function
(options) {
$.ajax({
url: prime.data.queryTool + options.url,
dataType:
'jsonp'
,
contentType:
'application/json'
,
type:
'POST'
,
data: options.crud.data,
success:
function
(data, textStatus, jqXHR) {
options.crud.success(data);
},
error:
function
(jqXHR, textStatus, errorThrown) {
options.crud.error(jqXHR);
},
complete:
function
(jqXHR, textStatus) {
console.log(
'-----------------------------------'
);
console.log(
'response from '
+ options.url +
':'
);
console.log(jqXHR);
console.log(
'-----------------------------------'
);
}
});
}
I realize I could probably do this in the prime.dsCrud function's "data" configuration, but I would prefer to leave this function more generic. Can anyone explain to me why my transport.parameterMap isn't firing?
Thanks!