如何在销毁剑道网格后成功提醒删除?

时间:2014-06-03 07:25:36

标签: jquery asp.net-mvc razor kendo-grid

我正在使用Kendo Grid来显示数据。现在我知道如何通过剑道网格确认删除。现在我希望在成功删除记录后显示像Delete Successfully一样的警报。我该怎么做?这是我的剑道网格代码。

    @(Html.Kendo().Grid<RxConnectEntities.DeleteFileDTO>().Name("deleteList")
    .Columns(columns =>
    {
        columns.Bound(p => p.DeleteFaxID).Hidden(true);
        columns.Bound(p => p.FaxName).Width(100).Title("File Name");
        columns.Bound(p => p.PerformedDateTime).Width(75).Title("Archive Date").Format("{0:MM/dd/yyyy}");
        columns.Command(command => { command.Destroy().Text("Move"); }).Width(50);
        columns.Bound(p => p.FilePath).Hidden(true);
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine).DisplayDeleteConfirmation("Are you sure want to Move this Finance File?"))
    .Pageable(p => p.PageSizes(true))
        .Scrollable()
        .Sortable()
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
        .Events(events => events.Change("onChange"))
        .Groupable()
    .Filterable(filterable => filterable.Extra(false).Operators(operators => operators.ForString(str => str.Clear().StartsWith("Starts with").Contains("contains").IsEqualTo("Is equal to"))))
    .HtmlAttributes(new { style = "height:738px;" })
        .DataSource(dataSource => dataSource
        .Ajax().ServerOperation(true)
        .PageSize(20)
        .Model(m => m.Id(p => p.DeleteFileID))
        .Read(read => read.Action("GetFileList", "Fax"))
    .Destroy(update => update.Action("MoveFileFromArchiveToQueue", "Operation"))
        ))

2 个答案:

答案 0 :(得分:3)

更改为:

.Events(events => events.Change("onChange").Remove("YourFunctionForAfterDelete")

然后从那确认...

另一种方法是创建一个自定义命令来删除,使用ajax并将成功/错误消息返回到对话框或类似的东西中,这样更好但需要更多的代码和阅读。

columns.Command(commands =>
                      {
                          commands.Edit() data items
                          commands.Custom("Delete").Click("DeleteByAJAX"); // The "destroy" command removes data items
                      }).Width(95);

答案 1 :(得分:1)

我尝试了上述方法,无法根据需要使其工作。我改为订阅了onRequestEnd方法。我有几条警告信息需要抛出。 1表示成功添加记录,1表示成功删除记录,1表示成功更新记录。

我根据正在发生的CRUD操作在控制器中填充了ViewBag。

然后我在视图中检查Viewbag的值,并在页面重新加载时抛出正确的引导警报...

@if (ViewBag.Alert == "Success")
{
<div class="alert alert-success alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <strong>Record has been successfully added.</strong>
</div>
}

@if (ViewBag.Alert == "Deleted")
{
<div class="alert alert-success alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <strong>Record has been successfully deleted.</strong>
</div>
}

@if (ViewBag.Alert == "Updated")
{
<div class="alert alert-success alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <strong>Record has been successfully updated.</strong>
</div>
}

当网格添加记录,更新记录或通过使用以下javascript检测操作来删除记录时,我能够重新加载页面....

<script>
function onRequestEnd(e)
{
    var operationType = e.type;

    if(operationType == "destroy" || operationType == "create" || operationType == "update")
    {
        location.reload();
    }
}
</script>