How to get the total count out of JSON oData using the Kendo Grid Html Helper.

2 posts, 1 answers
  1. Rob
    Rob avatar
    3 posts
    Member since:
    Sep 2015

    Posted 11 Sep 2015 Link to this post


    I am having problems getting the total count field from JSON odata using the Html Helper for the Kendo Grid. Getting the odata.count value using JavaScript is fine though but our preference is to use the MVC html helper. The following is both examples:


    Using MVC Html Helper produces the following JavaScript error: Uncaught TypeError: Cannot read property 'count' of undefined. See the Schema property for where we are trying to get the oData.count.

        .Columns(columns =>
            columns.Bound(e => e.Field1).Filterable(false);
            columns.Bound(e => e.Field2);
            columns.Bound(e => e.Field3);
        .DataSource(dataSource => dataSource
            .Schema(schema =>
            .Transport(transport =>
                transport.Read(read => read.Url("/odata/DataUrl).DataType("json"));

    Using the following JavaScript works:

                dataSource: {
                    type: "odata",
                    transport: {
                        read: {
                            url: "/odata/DataUrl",
                            dataType: "json"
                    schema: {
                        data: function(data) {
    return data['value'];
                        total: function(data) {
                            return data['odata.count'];
                        model: {
                            fields: {
                                Field1: { type: "date" },
                                Field2: { type: "string" },
                                Field3: { type: "string" },
                    pageSize: 20,
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                filterable: true,
                sortable: true,
                pageable: true,
                columns: [
                        field: "Field1",
                        filterable: false,
                        format: "{0:MMM dd, yyyy}"
                        field: "Field2",
                        filterable: false
                        field: "Field3",
                        filterable: false




    Looking in the documentation there are only examples of this using javascript, are there some examples using the html helpers as well somewhere? Any pointers in the right direction are welcome.



  2. Answer
    Alexander Popov
    Alexander Popov avatar
    1442 posts

    Posted 15 Sep 2015 Link to this post

    Hi Rob,

    The Custom DataSource builder allows a JavaScript function to be used for the through a method override. For example: 
    .Total(@<text>function(data) { return data['odata.count']; }</text>))

    Alexander Popov
    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
Back to Top