We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to bind JSON data to Grid using Javascript?

I am using syncfusion grid in my project and want to bind JSON format data to grid.But data not display in grid.I have attached sample project.Please let me know how can I achieve it.Can it is not possible to bind JSON format data to grid.I have attached sample project for your reference and in that project I have created hard coded JSON format data but actual data from database and using following line of code we convert it into JOSN format.
                       var JSONString = JsonConvert.SerializeObject(dt);//dt is my datatable

Please help me its urgent.

Attachment: SyncfusionSample_e2f12174.rar

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team April 25, 2016 11:38 AM UTC

Hi Pankaj, 

You are serializing the object to json string using SerializeObject before binding them to Grid which is the cause of the problem. The Grid will accept the result as a LIST of JSON objects and not the JSON string. So we suggest to convert the dataTable and return them as a list. Refer to the following code example. 

        public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm) 
        { 
 
            using (SqlConnection cn = new SqlConnection(connectionStr)) 
            { 
                cn.Open(); 
 
                //Getting the records based on skip and top value. 
                SqlCommand cmd = new SqlCommand("SELECT OrderID,CustomerID,EmployeeID,Freight,OrderDate FROM Orders", cn); 
                SqlDataAdapter da = new SqlDataAdapter(cmd); 
                da.Fill(ds); 
                dt = (DataTable)ds.Tables[0]; 
                . . . . . 
            }  
            var order = (from DataRow row in dt.Rows 
                         select new Order 
                         { 
                             OrderID = Convert.ToInt32(row["OrderID"]), 
                             CustomerID = row["CustomerID"].ToString(), 
                             Freight = Convert.ToDecimal(row["Freight"]), 
                             EmployeeID = Convert.ToInt32(row["EmployeeID"]), 
                             OrderDate = Convert.ToDateTime(row["OrderDate"]) 
                         }).Skip(dm.Skip).Take(dm.Take).ToList(); 
            return Json(new { result = order, count = count }, JsonRequestBehavior.AllowGet);  
        } 

We have prepared a sample that can be downloaded from the following location. 


Regards, 
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon