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

Can't render data on grid

2 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kinnary
Top achievements
Rank 1
Kinnary asked on 15 Oct 2013, 07:52 PM
Hi

I am passing data to a kendoUI gird and the data doesn't display.
I'm new to this and am probably making a basic mistake.

My controller code is:

public ActionResult GetDataFromStream(string streamName)
{
string temp = OpenHttpGETConnection(streamName);
string[] split = temp.Split(new Char [] {'\r'});

//var myList = new List<dynamic>();
List<DisplayData> myList = new List<DisplayData>();

foreach (string s in split)
{
if(s!=null){
string[] strTemp = new string[2];
strTemp = s.Split(new Char[] { '\t' });

myList.Add
(new DisplayData
     {
key = strTamp[0]
value = strTemp[1]
});
 }
}
return Json(myList);

}

My index.cshtml code is:

function functionOne(streamName) {
console.log("@Url.Action("GetDataFromStream", "Index")" + "?streamName=" + encodeURIComponent(streamName));
$.ajax({

url: "@Url.Action("GetDataFromStream", "Index")" + "?streamName=" + encodeURIComponent(streamName),

success: OnSuccess,

});

}

function OnSuccess(data) {
//document.getElementById('dataTable').style.visibility = "visible";
myData = data;

$('#dataTable').kendoGrid({
dataSource: { transport: { read: { url: '@Url.Action("GetDataFromStream", "Home")', type: 'POST' } } },
scrollable: true,
toolbar: 'Metrics',
});

The grid get displayed but there is no data in it.
When I try to display myData[0][0], that displays fine.
But I want to display all the rows in data.

Thanks,
Kinnary

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 16 Oct 2013, 01:22 PM
Hi Kinnary,

 
From the provided information it seems that the Grid is not working due to invalid configuration. I would suggest to check the following step-by-step guides which demonstrate how to bind the KendoUI Grid for ASP.NET MVC wrapper to a data on the server using Ajax binding: 

Also I would suggest to check our CodeLibrary for more examples of KendoUI Grid.

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Oct 2013, 01:32 PM
Hello,
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

public  JsonResult GetDataFromStream([DataSourceRequest]DataSourceRequest request, string streamName)
        {
string temp = OpenHttpGETConnection(streamName);
string[] split = temp.Split(new Char [] {'\r'});
  
//var myList = new List<dynamic>();
List<DisplayData> myList = new List<DisplayData>();
  
foreach (string s in split)
{
if(s!=null){
string[] strTemp = new string[2];
strTemp = s.Split(new Char[] { '\t' });
  
myList.Add
(new DisplayData
     {
key = strTamp[0]
value = strTemp[1]
});
 }
}
             
            DataSourceResult result = myList.ToDataSourceResult(request);
            return Json(result);
        }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Kinnary
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Jayesh Goyani
Top achievements
Rank 2
Share this question
or