- The grid fires all "read", "create", "update" and "destroy" action methods from the controller when I use: "kendo.data.GanttDataSource" but when I use "kendo.data.DataSource", the grid only fires "read".
- When I hit "Add new record" button and fill all the details, one corresponding create action method is fired (which is successful) but also fires multiple failed update action method (the number of these fires is equal to number of rows in the grid)
- When I hit delete, Delete event is triggered for all the records thus making my grid empty.
<script>
$(document).ready(function () {
var datasource = new kendo.data.GanttDataSource({
type: "json",
transport: {
read: {
url: '@Url.Action("Details", "Student")',
//url: "/Student/Details",
dataType: "json",
type: "GET"
},
create: {
url: '@Url.Action("AddStudent", "Student")',
//url: "/Student/AddStudent",
dataType: "json",
type: "POST"
},
update: {
url: '@Url.Action("UpdateStudent", "Student")',
//url: "/Student/UpdateStudent",
dataType: "json",
type: "POST"
},
destroy: {
//url: '@Url.Action("DeleteStudent", "Student")',
url: "/Student/DeleteStudent",
dataType: "json",
type: "POST"
},
parametermap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
},
pageSize: 2,
schema: {
model: {
id: "rollno",
fields: {
rollno: { from: "rollno", type: "number" },
name: { from: "name", type: "string" },
address: { from: "address", type: "string" }
}
}
}
}
});
dataSource: datasource,
columns: [
{
field: "rollno",
title: "Roll No."
},
{
field: "name",
title: "Name"
},
{
field: "address",
title: "Address"
},
{ command: [ "edit", "destroy"], titlt:" "}
],
toolbar: ["search", "create"],
//autobind: true,
autosync: false,
filterable: true,
sortable: true,
editable: "inline",
pageable: true,
save: function (e) {
setTimeout(function () {
//$("#stdGrid").data("kendoGrid").refresh();
$("#stdGrid").data("kendoGrid").dataSource.read();
}, 200);
}
});
});
</script>
<style type="text/css">
.k-grid-search {
margin-left: auto;
margin-right: 0;
}
</style>
Hi Shamanth,
I tried to replicate the issue locally but to no avail. The requests are sent as expected on my end. In the Dojo example linked here I used the configuration provided in your reply. As you will see, the Grid is working as expected with DataSource configured.
Could you please send us an isolated runnable sample or modify the Dojo example in order to replicate the behavior the way it is at your side and send it back for a review? This way we could take a closer look and provide further assistance.
Looking forward to your reply.
Regards,
Neli
// This code was written according to GanttdataSource
--------------Backend code--------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ADO_KendoUIApp.Models;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using Newtonsoft.Json;
namespace ADO_KendoUIApp.Controllers
{
public class StudentController : Controller
{
private readonly SqlConnection con;
public StudentController()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
}
// GET: Student
public ActionResult Index()
{
Details();
return View();
}
//GET: Student/Details
public ActionResult Details()
{
SqlCommand cmd = new SqlCommand("select * from students", con);
con.Open();
var res = cmd.ExecuteReader();
List<db_Student> std = new List<db_Student>();
while (res.Read())
{
db_Student sobj = new db_Student();
sobj.rollno = (int)res[0];
sobj.name = (string)res[1];
sobj.address = (string)res[2];
std.Add(sobj);
}
con.Close();
ViewData["stud"] = std;
return Json(std, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public ActionResult AddStudent(FormCollection options)
{
int rollno = Convert.ToInt32(options[12]);
string name = options[13];
string address = options[14];
//List<db_Student> ls = JsonConvert.DeserializeObject<List<db_Student>>(options[0]);
SqlCommand cmd = new SqlCommand("insert into Students values ("+rollno+", '"+name+"', '"+address+"')", con);
con.Open();
var res = cmd.ExecuteNonQuery();
con.Close();
return View();
}
[HttpPost]
public ActionResult UpdateStudent(FormCollection options)
{
return View();
}
[HttpPost]
public ActionResult DeleteStudent(FormCollection options)
{
int rollno = Convert.ToInt32(options[0]);
string name = options[1];
string address = options[2];
//List<db_Student> ls = JsonConvert.DeserializeObject<List<db_Student>>(options[0]);
SqlCommand cmd = new SqlCommand("delete from Students where rollno = " + rollno , con);
con.Open();
var res = cmd.ExecuteNonQuery();
con.Close();
return View();
}
}
}
Hi Shamanth,
It is hard to suppose what is the reason for the observed issue based on the provided information. I would suggest you take a look at the following sample project in the 'kendo-examples-asp-net-mvc' GitHub repository. For convenience below you will find links to the respective view and controller:
- https://github.com/telerik/kendo-examples-asp-net-mvc/blob/master/grid-crud/Views/Home/Index.cshtml
- https://github.com/telerik/kendo-examples-asp-net-mvc/blob/master/grid-crud/Controllers/HomeController.cs
You could try to configure the Grid the same way as in the sample project and test the behavior at your side.
I hope this helps.