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

Server side grouping - Web grid

3 Answers 1311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kirsty
Top achievements
Rank 1
Kirsty asked on 12 Nov 2014, 01:26 PM
Hi
I am busy doing a POC to figure out if Kendo Web Grid will fulfill all our requirements for a grid. I am currently stuck with server side grouping. 
Please can I ask for some clarity on how to handle the response from the server for grouping.
The grid is not grouped by default, but they can choose to group by any of the columns..one or more..so the response needs to know this as well.
We are using the HTML/Js version of the grid with Ruby on Rails. 

Our data is created from a backend query that is formatted into json. 

eg: of our response with no grouping :
{"items":[{"countries":{"name":"South Africa","iso_alpha_2":"ZA","iso_alpha_3":"ZAF"}},...

The grid is initialized like this
  dataGrid.kendoGrid({
           dataSource: data_source,
           groupable: true,
           sortable: true,
           pageable: {
              refresh: true
           },
           columns:  [
              #{columns_json}
           ]
        });
and our Datasource like this:
     data_source = new kendo.data.DataSource({
           transport: {
                read:  {
                    url: "#{data_table.url}",
                    dataType: "json"
                },
                parameterMap: function (options, operation) {
                    return options;
                }
           },
           batch: true,
           pageSize: 10,
           serverGrouping: true,
           serverPaging: true,
           schema: {
                data: function(response){
                   if (response.items) {
                      return response.items;
                  } else return null;
                },
                total: function (response) {
                   if (response.items)
                       return response.total_count;
                   else
                       return 0;
                }
           }
        });

How must the server response be formatted if a person has grouped by a column? I am assuming the response format is different if it is grouped compared to if it isn't...how can that scenario be easily handled as well?

I hope I am clear in my request.

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 14 Nov 2014, 09:55 AM
Hello Kirsty,

The server response format for serverGrouping is explained here:
Please check the article and let me know if you have any further questions.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Andrew
Top achievements
Rank 1
answered on 21 Jul 2020, 12:06 PM

Hi

First of all sorry to conflict this thread.

I found ToDataSourceResult source code in https://github.com/kendo-labs/dlinq-helpers/blob/master/Kendo.DynamicLinq/QueryableExtensions.cs this location. But it looks like very old. Could you please update this source code with the latest for better understanding about ToDataSourceResult?

0
Alex Hajigeorgieva
Telerik team
answered on 23 Jul 2020, 10:08 AM

Hi, Andrew,

The code that you have found is not part of the Kendo.Mvc.dll and the Queryable extensions. They are a community effort and largely experimental as noted in the README.md

The ToDataSourceResult() extension method is designed to work with the built-in transports in ASP.NET MVC & ASP.NET Core and the source code is available in the accounts of licenced users when they navigate to the Downloads section.

It appears that you are testing out the jQuery Kendo UI Grid and using of the server-side extensions is not required. You can format your own response and structure the grid data source in such way that it can parse it. 

We have a runnable example in a sample Knowledge Base that can help you format the group response here:

https://docs.telerik.com/kendo-ui/knowledge-base/grid-format-of-the-response-with-server-grouping

On the other hand, there are developers who prefer to use JavaScript to build their grids but like to benefit from the server data and aggregation conducted in one line of code in their controllers, so they can use the MVC extensions with a built-in data source transport, for example:

 

"dataSource": {
     "type": "aspnetmvc-ajax",

 

Here is another forum post that shows that:

https://www.telerik.com/forums/jquery-grid-not-loading-data-even-though-json-is-returned#cyGhfScwlkCoxshn8cHGWQ

Let us know in case you have further questions.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Tags
Grid
Asked by
Kirsty
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Andrew
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or