admin 管理员组文章数量: 1086019
I have been trying to get this piece of code to work for a while now, and I have run out of ideas. I looked online and could not find anything helpful.
I have a grid defined which has a lists of persons. User can click on the person to add it to their contacts. I have a custom mand which does a post to my Action.
This is probably going to end up being something simple that I am overlooking..
I am unable to get the dataItem of the Grid. Following is the error I receive:
Uncaught TypeError: Cannot read property '0' of undefined
y.extend.dataItem
addContact
p.isFunction.f
p.event.dispatch
g.handle.h
Following is my Javascript function:
function addContact(e) {
debugger;
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr")); // <-- ERRORS HERE
var id = dataItem.Id
var url = "@Url.Action("AddContact", "Contacts")";
alert(url);
$.ajax({
url: url,
type: 'POST',
data: { contactID: id },
});
}
Grid:
@(Html.Kendo().Grid(ViewBag.Contacts as List<Contacts>)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.ReleaseDate);
columns.Command(mand => mand.Custom("Add").Click("addContact")).Width(80).HtmlAttributes(new { title = "Add Contact" });
})
.Groupable()
.Pageable()
.Sortable()
.Scrollable(s => s.Height("auto"))
.Filterable()
.DataSource(dataSource => dataSource
.Server()
.PageSize(50))
)
Used scripts:
<script src=".3.1315/js/jquery.min.js"></script>
<script src=".3.1315/js/kendo.all.min.js"></script>
<script src=".3.1315/js/kendo.aspnetmvc.min.js"></script>
<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>
I have been trying to get this piece of code to work for a while now, and I have run out of ideas. I looked online and could not find anything helpful.
I have a grid defined which has a lists of persons. User can click on the person to add it to their contacts. I have a custom mand which does a post to my Action.
This is probably going to end up being something simple that I am overlooking..
I am unable to get the dataItem of the Grid. Following is the error I receive:
Uncaught TypeError: Cannot read property '0' of undefined
y.extend.dataItem
addContact
p.isFunction.f
p.event.dispatch
g.handle.h
Following is my Javascript function:
function addContact(e) {
debugger;
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr")); // <-- ERRORS HERE
var id = dataItem.Id
var url = "@Url.Action("AddContact", "Contacts")";
alert(url);
$.ajax({
url: url,
type: 'POST',
data: { contactID: id },
});
}
Grid:
@(Html.Kendo().Grid(ViewBag.Contacts as List<Contacts>)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.ReleaseDate);
columns.Command(mand => mand.Custom("Add").Click("addContact")).Width(80).HtmlAttributes(new { title = "Add Contact" });
})
.Groupable()
.Pageable()
.Sortable()
.Scrollable(s => s.Height("auto"))
.Filterable()
.DataSource(dataSource => dataSource
.Server()
.PageSize(50))
)
Used scripts:
<script src="http://cdn.kendostatic./2012.3.1315/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic./2012.3.1315/js/kendo.all.min.js"></script>
<script src="http://cdn.kendostatic./2012.3.1315/js/kendo.aspnetmvc.min.js"></script>
<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>
Share
Improve this question
edited Jan 31, 2014 at 9:00
BLoB
9,7459 gold badges57 silver badges77 bronze badges
asked Feb 23, 2013 at 19:42
LeonLeon
1351 silver badge8 bronze badges
2 Answers
Reset to default 5In your JS you need to grab a reference to your grid instead of using this.
var grid = $("#Grid").data("kendoGrid");
var dataItem = grid.dataItem($(e.currentTarget).closest("tr"));
In the end, the issue was with the Grid configuration.
I had to set DataSource to Ajax binding instead of Server. Server binding prevents any client side data from being saved.
本文标签: aspnet mvcKendoUI Grid Get Cell value in JavascriptStack Overflow
版权声明:本文标题:asp.net mvc - Kendo-UI Grid Get Cell value in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744009970a2517969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论