This is a migrated thread and some comments may be shown as answers.

[Solved] Custom group parameter using parameterMap

3 Answers 193 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 12 Sep 2014, 10:31 PM
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
});

3 Answers, 1 is accepted

Sort by
0
Nick
Top achievements
Rank 1
answered on 12 Sep 2014, 10:33 PM
Specifically this the error line: jquery.js:10306
0
Nick
Top achievements
Rank 1
answered on 15 Sep 2014, 03:47 PM
Using uminified version of Kendo the error is traced to this line:

            that._pristineData = data.slice(0);

That's line # 7693 in kendo.all.js or line #2767 in kendo.data.js
0
Nick
Top achievements
Rank 1
answered on 15 Sep 2014, 07:10 PM
I finally realized that server grouping expects response data to be in a certain format. A small line with a sample would be HELPFUL!! Wasted 5 hours digging through the code!!
Tags
Data Source
Asked by
Nick
Top achievements
Rank 1
Answers by
Nick
Top achievements
Rank 1
Share this question
or