4

我正在研究 Kendo GridCRUD Operations并想使用它的内联编辑。在执行添加、删除或更新操作后,我想执行一些操作并刷新我的网格。

我已经看到了很多解决方案。他们建议了一些事件,例如"Change" , "RequestEnd"等。但是我的 RequestEnd 事件函数没有被调用,并且 Change Event 函数被调用,但是它在任何 CRUD 操作之前而不是在操作之后被调用。

同样,我试图检查ParameterMap在 Kendo Grid 的“”中执行了哪些操作,但它也在 CRUD 操作之前被调用。请建议我在任何 CRUD 操作之后实施网格重新加载的一些解决方案。这是我的代码:

@Imports [Shared].Models
@Imports [Shared].Enums
@code    

Layout = "~/Views/Shared/_AdminLayout.vbhtml"

@Styles.Render("~/Content/Kendo.min/css")  
@Scripts.Render("~/bundles/kendo")

Dim eventId As Guid = ViewData("EventId")

结束代码

<div>
    <br />
    Shift Grid Demo
    <br />
</div>

<div id="divEventsGrid">

    <div id="example" class="k-content">
        <div id="TestShiftGrid" style="width: 660px;"></div>
    </div>

</div>


</section>


<pre>

<script type="text/javascript">

    $(document).ready(function () {

        var crudServiceBaseUrl = '@Url.Action("JsonGetShiftList", "ManageEvents")' + "?eventId=" + '@eventId',
                   dataSource = new kendo.data.DataSource({
                       transport: {
                           read: {
                               url: '@Url.Action("JsonGetShiftList", "ManageEvents")' + "?eventId=" + '@eventId',
                               dataType: "json"

                           },
                           update: {
                               url: '@Url.Action("JsonShiftUpdate", "ManageEvents")' + "?eventId=" + '@eventId',
                               dataType: "jsonp",

                           },


                           destroy: {
                               url: '@Url.Action("JsonShiftDelete", "ManageEvents")' + "?eventId=" + '@eventId',
                               dataType: "jsonp",
                               success: function (data) {
                                   if (data == true) {
                                       alert("Record Updated Successfully")
                                   }
                               }
                           },

                           create: {

                               url: '@Url.Action("JsonShiftCreate", "ManageEvents")' + "?eventId=" + '@eventId',
                               dataType: "jsonp",
                               type: "Post"
                           },
                           parameterMap: function (options, operation) {
                               if (operation !== "read" && options.models) {
                                   return { models: kendo.stringify(options.models) };

                               }                  
                           }                         
                       },

                       change: function (e) {

                           // alert(e.type); == is not working it is showing undefined..
                           // e.action is showing my current operation but before the operation not after. 
                           if (e.action == "add")
                           {
                               $("#TestShiftGrid").data("kendoGrid").dataSource.read();
                           }


                       },
                       //requestEnd is unable to call. ?
                       requestEnd: function (data) {

                           $("#TestShiftGrid").data("kendoGrid").dataSource.read(); 
                       },
                       batch: true,
                       pageSize: 15,
                       schema: {
                           model: {
                               id: "ShiftId",
                               fields: {
                                   EventId: { editable: false, nullable: true },
                                   ShiftId: { validation: { required: true } },
                                   ShiftDate: { validation: { required: true } },
                                   FromTime: { validation: { required: true } },
                                   ToTime: { validation: { required: true } },

                               }
                           }
                       }
                   });

        $("#TestShiftGrid").kendoGrid({
            dataSource: dataSource,
            navigatable: true,
            toolbar: ["create"],
            pageable: true,
            sortable: true,
            height: 300,
            columns: [
                    {
                        field: "ShiftDate",
                        title: "Shift Date"
                    },
                    {
                        field: "FromTime",
                        title: "From Time"

                    },
                    {
                        field: "ToTime",
                        title: "To Time"

                    },
                    {
                        command: ["edit", "destroy"],
                        title: "&nbsp;",
                        width: "190px"
                    },

            ],
            editable: "inline"
        });

    });


</script>
</pre>
4

2 回答 2

3

数据源同步事件似乎非常适合这一点,它在创建、更新和删除操作之后调用。

于 2013-07-25T15:09:51.533 回答
1

您可以使用该dataSource requestEnd事件,如下所示:

requestEnd: function (e) {
        if (e.type != "read") {
            // refresh the grid
            e.sender.read();
        }
    }

从文档中:

Fired when a remote service request is finished.

于 2016-03-04T19:48:47.140 回答