我想在 Kendo Grid 中添加新行,该行在 First Cell 中具有默认值。 如何在添加的 Kendo Grid 行中设置默认值
我在 Kendo Grid 中添加新行为:
$('#AddSingleSuppliment').click(function () {
grid.addRow();
});
但我想根据单击的 DOM 元素的值设置第一个单元格的值,例如
$('#AddSingleSuppliment').click(function () {
var temVal=$(this).text();
grid.addRow(tempVal);
});
但是我们不能那样做。 因此,请帮助我解决这个问题,以便在 Kendo Grid 中添加新行,其中一个单元格具有单击的 Button 值。
现在我可以在 Kendo Grid 中添加新行了,
$("#AddSingleSupplement").click( function(){
var tempSupplement = $(this).val();
//alert(tempSupplement);
grid.addRow(tempSupplement);
grid.dataSource._data[0].Description = $(this).text().trim();
});
但是在添加新行时不直接显示值。它在我们点击其他元素后显示。 请建议我这是执行此操作的正确方法还是除此之外的任何其他方法。
最佳答案
对于动态默认值,您可以在 Edit 上连接您的逻辑事件,例如:
<script>
$('#AddSingleSuppliment').click(function () {
grid.addRow();
});
function onEdit(e)
{
//Custom logic to default value
var name = $("#AddSingleSuppliment").text();
// If addition
if (e.model.isNew()) {
//set field
e.model.set("Name", name); // Name: grid field to set
}
}
</script>
关于javascript - 使用一些默认值在 Kendo Grid 中添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20187113/