为Telerik UI for ASP.NET MVC编写复选框的脚本/函数和自定义删除按钮

问题描述 投票:1回答:1

我需要为ASP.NET MVC程序的Telerik UI编写脚本/函数的帮助。我的工具栏中有一个删除按钮,我认为我的脚本可以正确删除。现在,我被告知我的复选框中有一个脚本,当选中该脚本时也将被删除。作为C#编码器,我对Json编码并不完全了解。因此,任何帮助将不胜感激!这是我的下面的代码。

@(Html.Kendo().Grid<MVCSQLDatabase.Models>()
      .Name("Grid")
      .DataSource(dataSource => dataSource
          .Ajax()
          .PageSize(10)
          .Batch(true)
          .Model(model => model.Id(p => p.Proposal_Uid))
          .Read(read => read.Action("Proposals_Read", "Grid"))
          .Create(create => create.Action("Proposals_Create", "Grid"))
          .Update(update => update.Action("Proposals_Update", "Grid"))
          .Destroy(destroy => destroy.Action("Proposals_Destroy", "Grid"))
      )
          .Resizable(resize => resize.Columns(true))

      .Columns(columns =>
      {
          columns.Select().Width(100); //<-- my check boxes code.
          columns.Bound(c => c.Prime).Width(215);
          columns.Bound(c => c.Proposal).Width(200);
          columns.Bound(c => c.C).Width(190);
          columns.Bound(c => c.Cl).Width(185);
          columns.Bound(c => c.T).Width(290);
          columns.Bound(c => c.M).Width(220);
          columns.Bound(c => c.S).Format("{0: dd/MM/yyyy}").Width(170);
          columns.Bound(c => c.E).Format("{0: dd/MM/yyyy}").Width(170);
          columns.Bound(c => c.P).Width(235);
          columns.Bound(c => c.Con).Width(215);
          columns.Command(command => { command.Destroy(); }).Width(180);// <--- My delete button in my column
      })
      .ToolBar(toolbar =>
          {
          toolbar.Create();
          toolbar.Save();
          toolbar.Excel();
          toolbar.Custom().Text("Delete").Name("batchDestroy").IconClass("k-icon k-i-close"); //<-- my custom made delete button in my toolbar.
      })
      .ColumnMenu()
      .Editable(editable => editable.Mode(GridEditMode.InCell))
      .Pageable()
      .Selectable(selectable =>
          {
          selectable.Mode(GridSelectionMode.Multiple);
          selectable.Type(GridSelectionType.Row);
      })
      .PersistSelection()
      .Filterable(filterable => filterable.Mode(GridFilterMode.Row))
      .Scrollable()
      .HtmlAttributes(new { style = "height:835px;" })

)

    <script>
        $("#grid").on("click", "batchDestroy", function() {
        var $tr = $(this).closest("tr"),
        grid = $("#grid").data("kendoGrid"),
        dataItem = grid.dataItem($tr);
        grid.dataSource.remove(dataItem);
});
    </script>
json telerik kendo-grid telerik-grid telerik-mvc
1个回答
0
投票

这里是其他陷入这种情况的人的代码。最让我兴奋的是.done函数,该函数可以结束按钮单击功能,然后在删除后保存网格。希望这对其他人有帮助!


 <script>
        $(document).ready(function ()
        {
            $(".k-grid-Destroy").on("click", function (e)
            {
                e.preventDefault();
                var grid = $("#Grid").data("kendoGrid");
                var selectedRows = grid.select();
                kendo.confirm(kendo.format("Are you sure you wish to delete {0} records?", selectedRows.length))
                    .done(function ()
                    {
                        $.each(selectedRows, function (i, row)
                        {
                            grid.removeRow(row);
                        })
                        grid.saveChanges();
                    });
            });
        });
    </script>


© www.soinside.com 2019 - 2024. All rights reserved.