本文介绍了在kendo网格多选框中选中了在mvc4中的jQuery读取时仅获取一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的剑道网格
@(Html.Kendo().Grid(Model)
.Name("grid1")
.Columns(columns =>
{
columns.Bound(p => p.Associate).ClientTemplate("<input id='assetcheck' name='assetcheck' type='checkbox' #= Associate == 'true' ? checked='checked':'' # class='chkbx'/>").Width(35).HeaderTemplate("<input id='checkall' type='checkbox' onclick='checkAll(this)'>").Filterable(false).Sortable(false);
// columns.Bound(p => p.IsAttached).ClientTemplate("<input type='checkbox' #= IsAttached == 'true' ? checked='checked' : '' # onclick='attachedchanged(this);' />");
columns.Bound(p => p.AssetNumber).Title("Asset Number");// #= AssetId @<text></text> ':'' # onclick='attachedchanged(this); == 'true'
columns.Bound(p => p.AssetName);
columns.Bound(p=>p.ParentAsset);
columns.Bound(p => p.ParentCompany).Title("Company");
columns.Bound(p => p.AssetId).Hidden();
})
// .Pageable()
.Sortable()
.Scrollable(scr => scr.Height(400))
.Filterable()
.Selectable(s => s.Mode(GridSelectionMode.Multiple))
// .Events(events => events.Change("Grid_OnRowSelectUID"))
//.Pageable(pageable => pageable
// .Refresh(true)
// .PageSizes(true)
// .ButtonCount(5))
.DataSource
(
dataSource => dataSource
.Ajax()
// .PageSize(10)
.ServerOperation(false)
.Read(read => read.Action("GetAssociateAssetParent", "Asset").Data("getMsgType"))
// .Model(model => model.Id(p => p.AssetId))
)
)
在保存"按钮中,点击通话
In save button click am calling
$('#btnsave').click(function (e){
var UsedBooks = "";
var grid = $("#grid1").data("kendoGrid");
grid.select().each(function () {
var dataItem = grid.dataItem($(this));
UsedBooks += dataItem.AssetId + ",";
});
}
在网格中,我选择了两个复选框,但是这里获得了第二个值...第一个值没有获得到UsedBooks
In grid am selecting two checkboxs but here am getting second value ...first value am not getting to UsedBooks
推荐答案
// getting kendo grid
var grid = $("#grid1").data("kendoGrid");
// list of selected and unselected books
var books = [];
// getting all the checked rows
grid.tbody.find("input:checked").closest("tr").each(function (index) {
grid.select($(this));
var dataItem = grid.dataItem($(this));
dataItem.assetcheck = 'true';
books.push(dataItem);
});
// getting all the unchecked rows
grid.tbody.find("input:not(:checked)").closest("tr").each(function (index) {
grid.select($(this));
var dataItem = grid.dataItem($(this));
dataItem.assetcheck = 'false';
books.push(dataItem);
});
最终在ajax调用中发送所有数据并保存.
finally in ajax call send the whole data and save.
这篇关于在kendo网格多选框中选中了在mvc4中的jQuery读取时仅获取一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!