Kendo grid server-side grouping, return value property "Items" instead of "items" cause exception in kendo.all.js

2 posts, 0 answers
  1. Claudio
    Claudio avatar
    21 posts
    Member since:
    Feb 2015

    Posted 04 Nov 2015 Link to this post

    Hi, my KendoUI version is v2015.2.902, i use a kendo grid for server paging, sorting, filtering and now i would like to add grouping functionality.
    I use "function read" mode for dataSource calling asp.net mvc controller method. (server side request object is a Kendo.Mvc.UI.DataSourceRequest object)
    this is my dataSource configuration:

    let dataSource: any = {
      batch: true,
      serverPaging: true,
      serverSorting: true,
      serverFiltering: true,
      serverGrouping: true,
      page: 1,
      pageSize: 20,
      transport:
      {
          read: function (options)
          {
              kendo.data.transports["aspnetmvc-ajax"].fn.options.options = { prefix: '' };
              let request = kendo.data.transports["aspnetmvc-ajax"].fn.options.parameterMap(options.data, "read", false);

              thisObject.httpService.GetNodes(request)
              .then(function (args: IHttpServiceParameters)
              {
                  options.success(args.data);
              });
          }
      },
      schema:
      {
          data: function (data)
          {
              return data.Data;
          },
          total: function (data)
          {
              return data.Total;
          },
          groups: function (data)
          {
              return data.Data;
          },
          model: model
      }
    };

    if i not use grouping all work fine, but using grouping the data result object seem not binding correctly.

    args.data.Data returned from server has this schema:

    [{ AggregateFunctionsProjection: null, 
       Aggregates: {}, 
       HasSubGroups: false, 
       Items: [],      <--- Keep note of this element name
       Key: "Invoice", 
       Member: "InvoiceColumnName", 
       Subgroups: [], 
       value: undefined 
     }, 
    ...]

    the problem is when kendo.all.js parse the response of the server, passed from args.data.Data to convertGroup function (kendo.all.js line 7049)
    in this function there is a call who reference to record.items object but the object in data returned from server is called Items (starting with uppercase)

    kendo.all.js code:
    function convertGroup(data, getters, modelInstance, originalFieldNames, fieldNames) {
          var record,
              idx,
              fieldName,
              length;

          for (idx = 0, length = data.length; idx < length; idx++) {
              record = data[idx];

              fieldName = originalFieldNames[record.field];
              if (fieldName && fieldName != record.field) {
                  record.field = fieldName;
              }

              record.value = modelInstance._parse(record.field, record.value);

              if (record.hasSubgroups) {
                  convertGroup(record.items, getters, modelInstance, originalFieldNames, fieldNames);    <--- Here the problem !!
              } else {
                  convertRecords(record.items, getters, modelInstance, originalFieldNames, fieldNames);  <--- Here the problem !!
              }
          }
      }

    do you have any suggestion? why the object returned from server have Items property insted of items?
    How to solve?
    In attachment the google developer tools screenshot.

    Thanks
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 06 Nov 2015 Link to this post

    Hello Claudio,

    Indeed, the data returned by the DataSourceResult will not exactly match the data expected by the DataSource. This is handled by the aspnetmvc-ajax schema implementation as it is designed to work with the DataSourceResult data. Thus, you should use the aspnetmvc-ajax schema group and aggregates (if needed) function or convert the data on your own.

    schema:
    {
        data: function (data)
        {
            return data.Data;
        },
        total: function (data)
        {
            return data.Total;
        },
        groups: kendo.data.schemas["aspnetmvc-ajax"].groups,
        model: model
    }

    Regards,
    Rosen
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top