0

I have am successfully grouping my datasource's data server-side for a mobile listview, however, I cannot display it to the screen. The data in _pristine data correctly shows my data in the following structure:

results: Array[12] // 12 groups total
             0 = Array[5] // first group
                 0 = Object // groupID lives here
total: 14

Here is the relevant section of my datasource definition:

schema: {
    groups: "[d.results]", // tried function(response) {return [response.d.results];}
    data: "d.results",
    total: "d.total",
},
serverGrouping: true,
group: "groupID",
.
.
.

My datasource works fine with client side grouping..

TAS
  • 383
  • 1
  • 6
  • 17

1 Answers1

0

When I used it like this, I got it correctly,

        serverFiltering: true,
        serverGrouping: true,
        serverSorting: true,
        serverPaging: true,
        page: 1,
        pageSize: 10,
        schema: {
            data: "results",
            groups: "groups",
            total: "total",
            model: {
                id: "id"
            }
        }

In the serverside,

    // $group_by is the string, which is processed from the $_GET['group']
    // $results are the results grouped by

    $groups = array();

    if (!empty($group_by)) {
        foreach ($results as $result) {                
            $group_result = function_to_get_results_of_one_group($result['some_field']);                
            $groups[] = array(
                'field' => "The name of the field we want to display in the group by",
                'value' => "The value of the field we want to display in the group by",
                'items' => $group_result,
                'hasSubgroups' => FALSE,
                'aggregates' => array()
            );
        }
    }

    echo json_encode(
            array(
                'results' => $results,
                'groups' => $groups,
                'total' => $countPdct
            )
    );
    exit;

I am not sure, if this is the most efficient way to get the records in the server side. If somebody have a better idea to fetch the records in a more efficient way, please suggest.

Hope this helps someone looking for Servergrouping in kendo datasource.

Ajeesh Joshy
  • 1,387
  • 2
  • 18
  • 32