Javascript 按enter键后,将焦点设置为下一个剑道网格行
我目前有一个分层剑道网格,在那里我可以批量编辑一些细节列。我已经激活了自动同步,所以我只需要失去我编辑的单元格的焦点,或者按enter键,它就会自动保存 到目前为止,这是可行的,但我现在需要的是,当用户在单元格中按enter键时,焦点将更改为下一行,同一列 我会用文字表达我的背景。我有一份车辆清单。我可以展开这些行,以便查看所选汽车的预订列表。在给定的时间后,用户将在每次预订后输入车辆的里程数。假设车辆有10个预订。当用户输入第一个里程数据,然后按enter键时,焦点将切换到下一行,用户可以输入下一个里程。这10个保留区也是如此。我真的不知道如何做到这一点,我想我应该寻求帮助 这是我的相关代码 主网格:Javascript 按enter键后,将焦点设置为下一个剑道网格行,javascript,kendo-ui,kendo-grid,Javascript,Kendo Ui,Kendo Grid,我目前有一个分层剑道网格,在那里我可以批量编辑一些细节列。我已经激活了自动同步,所以我只需要失去我编辑的单元格的焦点,或者按enter键,它就会自动保存 到目前为止,这是可行的,但我现在需要的是,当用户在单元格中按enter键时,焦点将更改为下一行,同一列 我会用文字表达我的背景。我有一份车辆清单。我可以展开这些行,以便查看所选汽车的预订列表。在给定的时间后,用户将在每次预订后输入车辆的里程数。假设车辆有10个预订。当用户输入第一个里程数据,然后按enter键时,焦点将切换到下一行,用户可以输入
<div class="col-md-12">
@(Html.Kendo().Grid<ParcAutoMvc.ViewModels.VehiculeViewModel>()
.Name("gridListeVehicule")
.Events(e => e.DataBound("onDataBoundVehiculeReservation"))
.Columns(columns =>
{
columns.Bound(c => c.VehiculeID);
columns.Bound(c => c.Description);
columns.Bound(c => c.Marque.Description);
columns.Bound(c => c.Modele.Description);
columns.Bound(c => c.Annee);
})
.Groupable()
.NoRecords(e => e.Template("<div style='padding:30px 0;'><i>Aucun enregistrement à afficher</i></div>"))
.Pageable(e => e.Messages(mes => mes.Empty("Aucun enregistrement à afficher")))
.Sortable()
.ClientDetailTemplateId("client-template")
.AutoBind(false)
.Scrollable(s => s.Enabled(false))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(25)
.Read(read => read.Action("ListeVehiculeReservation", "Operation").Data("FiltreVehiculeReservation"))
)
.HtmlAttributes(new { @class = "small" })
)
</div>
@(Html.Kendo().Grid())
.名称(“交通工具”)
.Events(e=>e.DataBound(“OnDataBoundVehicleReservation”))
.列(列=>
{
columns.Bound(c=>c.VehicleId);
columns.Bound(c=>c.Description);
columns.Bound(c=>c.Marque.Description);
columns.Bound(c=>c.Modele.Description);
columns.Bound(c=>c.Annee);
})
.Groupable()
.NoRecords(e=>e.Template(“Aucun enregistrationáafficher”))
.Pageable(e=>e.Messages(mes=>mes.Empty(“Aucun enregistrementáafficher”))
.Sortable()
.ClientDetailTemplateId(“客户端模板”)
.AutoBind(假)
.Scrollable(s=>s.Enabled(false))
.DataSource(DataSource=>DataSource
.Ajax()
.页面大小(25)
.Read(Read=>Read.Action(“ListVehicleReservation”、“Operation”).Data(“FiltreVehiculeReservation”))
)
.HtmlAttributes(新的{@class=“small”})
)
详图网格:
<script id="client-template" type="text/x-kendo-template">
@(Html.Kendo().Grid<ParcAutoMvc.ViewModels.ReservationViewModel>()
.Name("grid_#=VehiculeID#") // make sure the Name is unique
.Events(e => e.DataBound("onDataBoundReservation").Edit("onEditReservation").Save("onSaveReservation"))
.Columns(columns =>
{
columns.Bound(c => c.Depart);
columns.Bound(c => c.Arrivee);
columns.Bound(c => c.Ville);
columns.Bound(c => c.Endroit);
columns.Bound(c => c.ReservePour);
columns.Bound(c => c.KMDepart).ClientTemplate("\\#=Statut == 0 ? 'Annulée' : KMDepart == -1 ? '' : KMDepart\\#");
columns.Bound(c => c.KMArrivee).ClientTemplate("\\#=Statut == 0 ? 'Annulée' : KMArrivee == -1 ? '' : KMArrivee\\#");
})
.Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode
.DataSource(dataSource =>
// Load reservations
dataSource.Ajax()
.Model(model =>
{
model.Id(r => r.Id);
model.Field(r => r.KMArrivee);
model.Field(r => r.KMDepart);
model.Field(r => r.Endroit).Editable(false);
model.Field(r => r.Depart).Editable(false);
model.Field(r => r.Arrivee).Editable(false);
model.Field(r => r.Ville).Editable(false);
model.Field(r => r.ReservePour).Editable(false);
model.Field(r => r.Id).Editable(false);
})
.Batch(true)
.AutoSync(true)
.Update(update => update.Action(actionName: "Grille_Modifier", controllerName: "Operation"))
.Read(read => read.Action("ListeReservation", "Operation").Data("FiltreReservation(#=VehiculeID#)"))
)
.Pageable(e => e.Messages(mes => mes.Empty("Aucun enregistrement à afficher")))
.ToClientTemplate()
)
</script>
@(Html.Kendo().Grid())
.Name(“grid##=VehicleId#”)//请确保名称唯一
.Events(e=>e.DataBound(“onDataBoundReservation”).Edit(“onEditReservation”).Save(“onSaveReservation”))
.列(列=>
{
columns.Bound(c=>c.Depart);
columns.Bound(c=>c.Arrivee);
columns.Bound(c=>c.Ville);
columns.Bound(c=>c.Endroit);
columns.Bound(c=>c.ReservePour);
columns.Bound(c=>c.KMDepart).ClientTemplate(\\\\\\\\=Statut==0?'annualée':KMDepart==1?“”:KMDepart\\\\\\\\”;
columns.Bound(c=>c.KMArrivee).ClientTemplate(“\\\\\\\\=Statut==0?”“无效”:KMArrivee==1?“:KMArrivee\\\\\”;
})
.Editable(Editable=>Editable.Mode(GridEditMode.InCell))//在单元格编辑模式下使用
.DataSource(DataSource=>
//载客预定
Ajax()
.Model(Model=>
{
model.Id(r=>r.Id);
model.Field(r=>r.KMArrivee);
字段(r=>r.kms);
model.Field(r=>r.Endroit).Editable(false);
model.Field(r=>r.Depart).可编辑(false);
model.Field(r=>r.Arrivee).可编辑(false);
model.Field(r=>r.Ville).Editable(false);
model.Field(r=>r.ReservePour).可编辑(false);
model.Field(r=>r.Id).可编辑(false);
})
.Batch(真)
.自动同步(真)
.Update(Update=>Update.Action(actionName:“格栅修饰符”,controllerName:“操作”))
.Read(Read=>Read.Action(“ListReservation”、“Operation”).Data(“FilterReservation(#=VehicleId”)
)
.Pageable(e=>e.Messages(mes=>mes.Empty(“Aucun enregistrementáafficher”))
.ToClient模板()
)
在我的脑海中,这是我的问题的相关代码。我知道我可能需要使用javascript来设置焦点,但我不知道如何设置。我设法得到了下一行的UID,但我不知道如何处理它,甚至不知道它是否对我想做的事情有用
function onSaveReservation(e) {
var uid = e.model.uid;
var idx = $(e.container).index();
var sender = e.sender;
dataView = this.dataSource.view();
for (var i = 0; i < dataView.length; i++) {
if (dataView[i].uid == uid) {
var vehiculeID = dataView[i].VehiculeID
if (dataView[i + 1] != null)
{
var nextUid = dataView[i + 1].uid;
}
}
}
}
保存函数(e){
var uid=e.model.uid;
var idx=$(e.container).index();
var sender=e.sender;
dataView=this.dataSource.view();
对于(var i=0;i
我非常感谢所有能帮助我解决问题的人。如果我不清楚我想做什么,请告诉我,英语不是我的第一语言。如果您需要我的代码,请随时索取更多示例。已经有一段时间了,但我发现了如何做我想做的事情,我想我会让人们知道,以防将来它对任何人都有帮助 我发布了很多代码,只保留了与下一行同一列的下一个单元格相关的内容。如果有人需要更多,请随时询问
//In my onSave Event I assign the next cell based on the selected car and row
gridReservation = $("#grid_" + vehiculeID);
rowEdited = gridReservation.data("kendoGrid").tbody.find("tr[data-uid='" + e.model.uid + "']").index();
nextRow = rowEdited + 1;
nextCell = '#grid_' + vehiculeID + ' tbody tr:eq(' + nextRow + ') td:eq(6)' //In my case I needed the 6th column;
//Then on my onDataBound event of my detail grid I set which cell I need to be editing
var theCell = $(nextCell);
gridReservation.data('kendoGrid').editCell(theCell);
希望它能帮助任何人