单击第一行的按钮时,如何获取下一行的对象详细信息?
How to get the Object details of the next row when clicking on a button in the first row?
我有一个 kendo 网格,每行都有模型详细信息,我想在单击一行上的按钮时交换两个对象的值。
例如:名称为 "Activity1" 的对象的订单号为“1”
名称对象 "Activity2" 的订单号为“2”
我想按 Activity 1 行上的一个按钮来交换订单号,这样 Activity 1 就会有订单号“2”,而 Activity 2 就会订单号为“1”。
我能够获取按下行对象的详细信息并将其更改为我想要的,但我无法获取下一行的详细信息来更改它,有什么帮助吗?
代码:
@(Html.Kendo().Grid<WEB02.ConfigurationModel.TestGrid>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(o => o.Name).Width(110);
columns.Bound(o => o.Type).Width(130);
columns.Command(command => {command.Destroy();
command.Custom("Higher Order").Click("HigherOrder");
});
})
.Sortable()
.Scrollable(scrollable => scrollable.Virtual(true))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple))
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.Name))
.PageSize(100)
.Read(read => read.Action("ActivityGrid", "Configuration"))
.Destroy("TestDelete", "Configuration")
.Events(events => events.Sync("sync_handler"))
)
.Pageable(pageable => pageable
.Refresh(true))
)
函数
function HigherOrder(e) {
var tr = $(e.target).closest("tr"); // get the current table row (tr)
var item = this.dataItem(tr);
// get the date of this row
//console.log(item);
console.log(item.NodeId);
console.log(item.Type);
console.log(item);
var newOrder= parseInt(item.ActivOrderNo)+1;
var params = {
nodeID: item.NodeId + ".CONFIG.OrderNumber",
write: newOrder
};
console.log(newOrder);
var temp = {
url: "/Configuration/WriteAttribute",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(params),
success: function (params) {
window.location.replace(params.redirect);
}
};
$.ajax(temp);
如果你只想得到下一行,你需要使用row.index
属性.
获取当前行索引:
var grid = $('[name="Grid"]').data("kendoGrid");
var dataRows = grid.items();
var rowIndex = dataRows.index(grid.select());
要按索引获取数据项,请使用下一个代码片段:
var nextDataItem = grid.dataItems()[rowIndex+1];
我有一个 kendo 网格,每行都有模型详细信息,我想在单击一行上的按钮时交换两个对象的值。 例如:名称为 "Activity1" 的对象的订单号为“1” 名称对象 "Activity2" 的订单号为“2”
我想按 Activity 1 行上的一个按钮来交换订单号,这样 Activity 1 就会有订单号“2”,而 Activity 2 就会订单号为“1”。
我能够获取按下行对象的详细信息并将其更改为我想要的,但我无法获取下一行的详细信息来更改它,有什么帮助吗?
代码:
@(Html.Kendo().Grid<WEB02.ConfigurationModel.TestGrid>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(o => o.Name).Width(110);
columns.Bound(o => o.Type).Width(130);
columns.Command(command => {command.Destroy();
command.Custom("Higher Order").Click("HigherOrder");
});
})
.Sortable()
.Scrollable(scrollable => scrollable.Virtual(true))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple))
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.Name))
.PageSize(100)
.Read(read => read.Action("ActivityGrid", "Configuration"))
.Destroy("TestDelete", "Configuration")
.Events(events => events.Sync("sync_handler"))
)
.Pageable(pageable => pageable
.Refresh(true))
)
函数
function HigherOrder(e) {
var tr = $(e.target).closest("tr"); // get the current table row (tr)
var item = this.dataItem(tr);
// get the date of this row
//console.log(item);
console.log(item.NodeId);
console.log(item.Type);
console.log(item);
var newOrder= parseInt(item.ActivOrderNo)+1;
var params = {
nodeID: item.NodeId + ".CONFIG.OrderNumber",
write: newOrder
};
console.log(newOrder);
var temp = {
url: "/Configuration/WriteAttribute",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(params),
success: function (params) {
window.location.replace(params.redirect);
}
};
$.ajax(temp);
如果你只想得到下一行,你需要使用row.index
属性.
获取当前行索引:
var grid = $('[name="Grid"]').data("kendoGrid");
var dataRows = grid.items();
var rowIndex = dataRows.index(grid.select());
要按索引获取数据项,请使用下一个代码片段:
var nextDataItem = grid.dataItems()[rowIndex+1];