[英]Add new Row in Kendo Grid with some default values
我想在Kendo Grid中添加新行,它在First Cell中具有默认值。 如何在添加的Kendo Grid行中设置默认值
我在Kendo Grid中添加了New Row ::
$('#AddSingleSuppliment').click(function () {
grid.addRow();
});
但我想在Clicked DOM元素的值的基础上设置第一个单元格的值,Like
$('#AddSingleSuppliment').click(function () {
var temVal=$(this).text();
grid.addRow(tempVal);
});
但我们不能以那种方式去做。 所以,请帮助我,在Kendo Grid中添加New Row,单击一个具有按钮值的单元格。
现在我可以在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>
根据Kendo团队,默认值无法动态更改。
但是,我们可以使用网格编辑事件来预先填充编辑表单:
edit: function(e) {
if (e.model.isNew() && !e.model.dirty) {
e.container
.find("input[name=ProductName]") // get the input element for the field
.val("MyCustomValue") // set the value
.change(); // trigger change in order to notify the model binding
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.