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

grid not displayed any record

4 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Quest Resource Management
Top achievements
Rank 1
Quest Resource Management asked on 05 Nov 2012, 11:32 AM

Hello,

Grid not displayed any record.

I want grid with autogeneratecolumn = true.

any help would be appreciated......

public ActionResult getData([DataSourceRequest]DataSourceRequest request)
        {
            List<Class1> c1s = new List<Class1>();
 
            for (int i = 0; i < 5; i++)
            {
                Class1 c1 = new Class1();
                c1.ID = i;
                c1.Name = "Name" + i;
                c1s.Add(c1);
            }
 
            return Json(c1s.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }

[Serializable]
  public class Class1
  {
      public int ID { get; set; }
      public string Name { get; set; }
  }


<
div id="mygrid">
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#mygrid").kendoGrid({
            dataSource: {
                type: "odata",
                serverPaging: true,
                serverSorting: true,
                pageSize: 100,
                transport: {
                    read: "/Home/getData"
                }
            },
            height: 280,
            scrollable: {
                virtual: true
            },
            sortable: true
        });
    });
</script>

Note : There is not any JS error.

If i tried with below read method then its works.

read: "http://demos.kendoui.com/service/Northwind.svc/Orders"

Thanks,
Jason

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 07 Nov 2012, 03:46 PM
Hi Jason,

The problem comes from the fact that the data array is not specified in the schema.data. Please add the following you your DataSource configuration:
schema: {
    data: "Data",
    total: "Total",
    aggregates: "AggregateResults",
    errors: "Errors"
}

I hope this will help.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Quest Resource Management
Top achievements
Rank 1
answered on 08 Nov 2012, 01:37 PM


Can you please explain, how to implement your changes in my code?
i have created MvcApplication1 (Default MVC4 application).

 

HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using MvcApplication1.Models;
using Kendo.Mvc.Extensions;
 
namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
 
            return View();
        }
 
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";
 
            return View();
        }
 
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
 
            return View();
        }
        public ActionResult getData([DataSourceRequest]DataSourceRequest request)
        {
            List<Class1> c1s = new List<Class1>();
 
            for (int i = 0; i < 5; i++)
            {
                Class1 c1 = new Class1();
                c1.ID = i;
                c1.Name = "Name" + i;
                c1s.Add(c1);
            }
 
            return Json(c1s.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
 
     }
}

Index.cshtml
@{
    ViewBag.Title = "Home Page";
}
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
@section featured {
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>@ViewBag.Title.</h1>
                <h2>@ViewBag.Message</h2>
            </hgroup>
            <p>
                To learn more about ASP.NET MVC visit
                <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc<;/a>.
                The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET MVC.
                If you have any questions about ASP.NET MVC visit
                <a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>.
            </p>
        </div>
    </section>
}
<h3>
    We suggest the following:</h3>
<ol class="round">
    <li class="one">
        <h5>
            Getting Started</h5>
        ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
        enables a clean separation of concerns and that gives you full control over markup
        for enjoyable, agile development. ASP.NET MVC includes many features that enable
        fast, TDD-friendly development for creating sophisticated applications that use
        the latest web standards. <a href="http://go.microsoft.com/fwlink/?LinkId=245151">Learn
            more…</a> </li>
    <li class="two">
        <h5>
            Add NuGet packages and jump-start your coding</h5>
        NuGet makes it easy to install and update free libraries and tools. <a href="http://go.microsoft.com/fwlink/?LinkId=245153">
            Learn more…</a> </li>
    <li class="three">
        <h5>
            Find Web Hosting</h5>
        You can easily find a web hosting company that offers the right mix of features
        and price for your applications. <a href="http://go.microsoft.com/fwlink/?LinkId=245157">
            Learn more…</a> </li>
</ol>
<div id="mygrid">
</div>
<div id="mygrid">
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#mygrid").kendoGrid({
            dataSource: {
                type: "odata",
                serverPaging: true,
                serverSorting: true,
                pageSize: 100,
                transport: {
                    read: "/Home/getData"
                }
            },
            height: 280,
            scrollable: {
                virtual: true
            },
            sortable: true
        });
    });
</script>

i have create Class1.cs in models folder.

Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace MvcApplication1.Models
{
    [Serializable]
    public class Class1
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
  
}

0
Accepted
Alexander Valchev
Telerik team
answered on 13 Nov 2012, 10:59 AM
Hi Jason,

I believe that there is a misunderstanding.
The data returned by the server seems to be OK, you have to edit your Kendo Grid configuration.
$("#mygrid").kendoGrid({
    dataSource: {
        //type: "odata",
        serverPaging: true,
        serverSorting: true,
        pageSize: 100,
        transport: {
            read: "/Home/getData"
        },
        schema: {
            data: "Data",
            total: "Total"
        }
    },
    height: 280,
    scrollable: {
        virtual: true
    },
    sortable: true
});

For more information please check the documentation of DataSource's configuration options.
In case you need further assistance I would like to ask you to open a support ticket preferably with a sample runnable project attached. In this way I would be able to examine your case in details and assist you further.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Nov 2012, 02:16 PM
Hello,

First create Table structure then convert this in to Kendo Grid.
$(document).ready(function () {
  $("#myActivityGrid").data("kendoGrid");
//OR
("#myActivityGrid").kendoGrid({ pageable: true,
        sortable: true
            });
 });

<table id="myActivityGrid">
           <thead>
               <tr>
                       <th style="text-align: center;">Header Name
                       </th>  
               </tr>
           </thead>
           <tbody>
                   <tr>
                       @foreach (var _var in Model.YourList)
                       {
                           <td>@_var.Data</td>
                       }
                   </tr>
           </tbody>
       </table>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Quest Resource Management
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Quest Resource Management
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or