admin管理员组文章数量:1244397
I am new to Kendo MVC ponents as well as to jQuery.
I am building a Kendo grid. I would like to hide the destroy (delete) mand in the grid on page load. After that, when I click a button on the page, it should be visible.
Kendo grid:
@(Html.Kendo().Grid<Model>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(product => product.DESCRIPTION).Title("Description");
columns.Bound(product => product.CODE).Title("Description");
columns.Command(mands =>
{
mands.Destroy().HtmlAttributes(new { id = "buttondelete" });
}).Title("Operations");
})
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add Records");
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable(pager => pager
.PageSizes(true)
.Input(true)
.Refresh(true)
)
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Events(events => events.Error("onError"))
.Model(model =>
{
model.Id(product => product.ID); // Specify the property which is the unique identifier of the model
model.Field(p => p.DESCRIPTION).Editable(false);
model.Field(product => product.CODE).Editable(false);
})
.Create(create => create.Action("a", "www"))
.Read(read => read.Action("b", "www"))
.Update(update => update.Action("c", "www"))
.Destroy(destroy => destroy.Action("d", "www"))
)
)
JS:
<script type="text/javascript">
$(document).ready(function () {
//$("#grid").find(".k-grid-delete").hide() // hide delete button
$("#grid").find(".k-toolbar").hide(); // hide toolbar
$(".k-grid-delete", "#grid").hide();
});
$('#EnableEdit').click(function () {
$("#grid").find(".k-toolbar").show();
// $(".k-grid-delete", "#grid").show();
var grid = $("#grid").data("kendoGrid");
grid.dataSource.at(0).fields["CODE"].editable = true;
grid.dataSource.at(0).fields["DESCRIPTION"].editable = true;
});
</script>
Edit: changed some parts according to first answer. Now
$(".k-grid-delete", "#grid").hide();
cannot hide k.grid-delete class. I guess JavaScript is loaded before the kendo grid is created. When I use it inside the click function of the edit button, it hides the delete buttons.
I am new to Kendo MVC ponents as well as to jQuery.
I am building a Kendo grid. I would like to hide the destroy (delete) mand in the grid on page load. After that, when I click a button on the page, it should be visible.
Kendo grid:
@(Html.Kendo().Grid<Model>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(product => product.DESCRIPTION).Title("Description");
columns.Bound(product => product.CODE).Title("Description");
columns.Command(mands =>
{
mands.Destroy().HtmlAttributes(new { id = "buttondelete" });
}).Title("Operations");
})
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add Records");
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable(pager => pager
.PageSizes(true)
.Input(true)
.Refresh(true)
)
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Events(events => events.Error("onError"))
.Model(model =>
{
model.Id(product => product.ID); // Specify the property which is the unique identifier of the model
model.Field(p => p.DESCRIPTION).Editable(false);
model.Field(product => product.CODE).Editable(false);
})
.Create(create => create.Action("a", "www"))
.Read(read => read.Action("b", "www"))
.Update(update => update.Action("c", "www"))
.Destroy(destroy => destroy.Action("d", "www"))
)
)
JS:
<script type="text/javascript">
$(document).ready(function () {
//$("#grid").find(".k-grid-delete").hide() // hide delete button
$("#grid").find(".k-toolbar").hide(); // hide toolbar
$(".k-grid-delete", "#grid").hide();
});
$('#EnableEdit').click(function () {
$("#grid").find(".k-toolbar").show();
// $(".k-grid-delete", "#grid").show();
var grid = $("#grid").data("kendoGrid");
grid.dataSource.at(0).fields["CODE"].editable = true;
grid.dataSource.at(0).fields["DESCRIPTION"].editable = true;
});
</script>
Edit: changed some parts according to first answer. Now
$(".k-grid-delete", "#grid").hide();
cannot hide k.grid-delete class. I guess JavaScript is loaded before the kendo grid is created. When I use it inside the click function of the edit button, it hides the delete buttons.
2 Answers
Reset to default 5If you use the same id
for each columns you have many elements with the same id
which is not legal. Try using the CSS class attribute that identifies a delete
button and on creation (page load) hide it and then on click show it.
Code for hiding them
$(".k-grid-delete", "#grid").hide();
Code for showing them back
$('#EnableEdit').click(function () {
$(".k-grid-delete", "#grid").show();
});
JSFiddle example here: http://jsfiddle/OnaBai/pSgeD/
For change kendo-grid setting, you must re-create your grid. You can ment out "for offlide data", if you gird binding to remote data.
setGridReadOnly: function (gridId, isReadOnly) {
var grid;
grid = $("#" + gridId).data("kendoGrid");
var myOpt = grid.options;
myOpt.editable.create = !isReadOnly;
myOpt.editable.destroy = !isReadOnly;
myOpt.editable.update = !isReadOnly;
if (isReadOnly == true)
myOpt.editable.mode = "null";
else
myOpt.editable.mode = "inline";
//for offlide data.
var data = grid._data;
//
grid.destroy();
$("#" + gridId).kendoGrid(myOpt).data("kendoGrid");
//for offlide data.
$("#" + gridId).data("kendoGrid").dataSource.data(data);
//
if (isReadOnly == true) {
$("#" + gridId).find(".k-grid-delete").hide();
$("#" + gridId).find(".k-grid-edit").hide();
$("#" + gridId).find(".k-grid-add").hide();
} else {
$("#" + gridId).find(".k-grid-delete").show();
$("#" + gridId).find(".k-grid-edit").show();
$("#" + gridId).find(".k-grid-add").show();
}
}
本文标签: javascriptKendo Grid HidingShowing Delete buttonStack Overflow
版权声明:本文标题:javascript - Kendo Grid HidingShowing Delete button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740169714a2235326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论