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

Group Problem

3 Answers 165 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 03 Apr 2012, 09:48 PM
I'm unsure of how to get the data grouped properly for a list view.  I think the problem is in my datasource definition although it may also be a problem with my list binding.  Any tips or suggestions for my data source are greatly appreciated.

I'm sending data in the following format from a webservice I have written:

{
  "count" : 3,
  "queryData" : "users",
  "results" : [
    { "length" : 2, "result" : "1A" },
    { "length" : 2, "result" : "9F" },
    { "length" : 3, "result" : "F03" }
  ]
}

And my datasource formatted as so:

var ds = new kendo.data.DataSource({
  transport: {
    read: {
      url: "http://localhost:12392/api/process",
      dataType: "jsonp",
      data: {
        queryData: 'users'
      }
    }
  },
  schema: {
    data: function(data) { return data.results },
    total: function(data) { return data.count },
    model: {
      fields: {
        length: {
          type: 'number'
        },
        result: {
          type: 'string'
        }
      }
    },
    group: { field: 'length' }
  }
});

Now I want my mobile list view to be grouped by length as the datasource is setup for. My mobile list view is not grouped. This grouping is not configurable by the user nor intended to be.  I just want my list grouped on length.

Fires on view render:

function resultsBind() {
    // Old local data version with correct grouping
    // $("#grouped-listview").kendoMobileListView({
    //           dataSource: kendo.data.DataSource.create({data: groupedData, group: "length" }),
    //           template: "#= result #",
    //           headerTemplate: "Group ${value}"
    //       });
    $("#grouped-listview").kendoMobileListView({
        dataSource: ds,
        template: "#= result #",
        headerTemplate: "Group ${value}"
    });
}

3 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 04 Apr 2012, 11:44 AM
I solved this by placing the 'group' option outside of the schema object.
0
Gema
Top achievements
Rank 1
answered on 14 Apr 2012, 02:36 AM
Hi Ryan, 

I'm having problem while implement server grouping. i need to know the structure of returned json needed and the kendo datasource schema.

I've seen you have solved it. could you post your final json and schema so i can study it ?

Thank you very much.

Regards,
0
Ryan
Top achievements
Rank 1
answered on 14 Apr 2012, 06:21 PM
Hey Gema,

Here you go.

Config:
  group: 'length',
  serverGrouping: true,
  schema: {
    groups: 'groups',
    total: 'count',
    model: {
      fields: {
        length: {
          type: 'number'
        },
        w: {
          type: 'string'
        },
        f: {
          type: 'string'
        }
      }
    }
  }
});


Data:
{
   count:3,
   input:"cab",
   limit:"10",
   skip:"0",
   len:3,
   groups:[
      {
         field:"length",
         value:"2",
         items:[
            {
               w:"ab",
               f:"ab"
            },
            {
               w:"ba",
               f:"ba"
            }
         ],
         hasSubgroups:false,
         aggregates:{
 
         }
      },
      {
         field:"length",
         value:"3",
         items:[
            {
               w:"cab",
               f:"cab"
            }
         ],
         hasSubgroups:false,
         aggregates:{
 
         }
      }
   ]
}
Tags
Data Source
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Gema
Top achievements
Rank 1
Share this question
or