Hello. I'm trying to talk to a Rails app using REST & json. I'm having problem passing custom group parameter. I tried various different hacks but nothing seems to work. Here my code ( I made it as simple as possible to make sure it run and I'm still getting an error)
The service I'm passing params to requires them to be passed like so:
http://localhost/products/search?page=1&per=10&group_by=manufacturer_id+asc&order_by=vendor_id+asc,vendor_number+desc
Sorting (order_by) - works fine. But grouping causes an error: Uncaught TypeError: undefined is not a function
Here is my code:
crudServiceBaseUrl = "/products";
productsDataSource = new kendo.data.DataSource({
autoSync: true,
pageSize: 10,
serverPaging: true,
serverSorting: true,
serverGrouping: true,
schema: {
data: "products",
total: "count"
},
batch: false,
transport: {
read: {
url: crudServiceBaseUrl + "/search",
dataType: "json",
contentType: "application/json",
type: "GET"
},
update: {
url: function(expense) {
return crudServiceBaseUrl + "/" + expense.id;
},
dataType: "json",
contentType: "application/json",
type: "PUT"
},
destroy: {
url: function(expense) {
return crudServiceBaseUrl + "/" + expense.id;
},
dataType: "json",
type: "DELETE"
},
create: {
url: crudServiceBaseUrl,
dataType: "json",
contentType: "application/json",
type: "POST"
},
parameterMap: function(data, type) {
if (type === "read") {
return {
page: data.page,
per: data.pageSize,
group_by: function() {
var groupings;
if (typeof data.group === "undefined") {
return "";
} else {
groupings = $.makeArray(data.group);
return $.map(groupings, function(g) {
return g.field + " " + g.dir;
}).join(",");
}
},
order_by: function() {
var sortings;
if (typeof data.sort === "undefined") {
return "";
} else {
sortings = $.makeArray(data.sort);
return $.map(sortings, function(s) {
return s.field + " " + s.dir;
}).join(",");
}
}
};
}
}
}
});
products_grid = $("#products_grid").kendoGrid({
dataSource: productsDataSource,
groupable: true,
sortable: {
mode: "multiple",
allowUnsort: true
},
pageable: true
});
The service I'm passing params to requires them to be passed like so:
http://localhost/products/search?page=1&per=10&group_by=manufacturer_id+asc&order_by=vendor_id+asc,vendor_number+desc
Sorting (order_by) - works fine. But grouping causes an error: Uncaught TypeError: undefined is not a function
Here is my code:
crudServiceBaseUrl = "/products";
productsDataSource = new kendo.data.DataSource({
autoSync: true,
pageSize: 10,
serverPaging: true,
serverSorting: true,
serverGrouping: true,
schema: {
data: "products",
total: "count"
},
batch: false,
transport: {
read: {
url: crudServiceBaseUrl + "/search",
dataType: "json",
contentType: "application/json",
type: "GET"
},
update: {
url: function(expense) {
return crudServiceBaseUrl + "/" + expense.id;
},
dataType: "json",
contentType: "application/json",
type: "PUT"
},
destroy: {
url: function(expense) {
return crudServiceBaseUrl + "/" + expense.id;
},
dataType: "json",
type: "DELETE"
},
create: {
url: crudServiceBaseUrl,
dataType: "json",
contentType: "application/json",
type: "POST"
},
parameterMap: function(data, type) {
if (type === "read") {
return {
page: data.page,
per: data.pageSize,
group_by: function() {
var groupings;
if (typeof data.group === "undefined") {
return "";
} else {
groupings = $.makeArray(data.group);
return $.map(groupings, function(g) {
return g.field + " " + g.dir;
}).join(",");
}
},
order_by: function() {
var sortings;
if (typeof data.sort === "undefined") {
return "";
} else {
sortings = $.makeArray(data.sort);
return $.map(sortings, function(s) {
return s.field + " " + s.dir;
}).join(",");
}
}
};
}
}
}
});
products_grid = $("#products_grid").kendoGrid({
dataSource: productsDataSource,
groupable: true,
sortable: {
mode: "multiple",
allowUnsort: true
},
pageable: true
});