自定义删除确认对话框kendo grid mvc

时间:2016-01-19 04:56:25

标签: asp.net-mvc kendo-grid

我有一个kendoui网格我希望用更好的彩色更改删除确认弹出窗口(而不是文本)。并显示删除的行记录     对于exmalpe:我确定删除这个rec​​ore:我的名字:amir     我们运行 deleteItem 但不运行。不要问题

     <body class="k-rtl">
        <div data-ng-app="app" data-ng-controller="MyCtrl">
            <kendo-grid options="gridOptions"></kendo-grid>
        </div>
        <div id="window"></div>
        <script type="text/javascript">
            angular.module("app", ["kendo.directives"]).controller("MyCtrl", function ($scope) {
                $scope.gridOptions = {
                    error: function (e) {
                        alert(e);
                    },

                    toolbar: ["pdf"],
                    pdf: {
                        allPages: true,
                        fileName: "Kendo UI Grid Export.pdf",
                        //proxyURL: "//demos.telerik.com/kendo-ui/service/export"
                    },

                    scrollable: true,
                    pageable: {
                        previousNext: true, // default true
                        numeric: true, // default true
                        buttonCount: 10, // default 10
                        refresh: true, // default false
                        input: true, // default false
                        //pageSizes: true, // default false
                        pageSizes: [5, 10, 15, 20, 25, 50, 100], //array of page size choices for user
                        info: true // show a label with current paging information in it
                    },

                    sortable: true,
                    filterable: true,
                    reorderable: true,
                    columnMenu: true,
                    groupable: true,

                    columns: [{
                        field: "", title: "ردیف", width: "80px", filterable: false, sortable: false, data: false,
                        template: "<span class='row-number' style=Text-a></span>"
                    },
                         {
                               template: "",
                             // "<div class='customer-photo'" +
                             //    "style='background-image: url(../content/web/Customers/#:data.CustomerID#.jpg);'></div>" +
                             //"<div class='customer-name'>#: ContactName #</div>",
                             field: "fullname", title: "نام ونام خانوادگی",
                             id: 'tet',

                             //   template: "<a  class = 'tet' href='@Url.Action("test", "Home")/#=id#'>#= FirstName #</a>"
                             template: "<a onclick='New()' class ='tet'  href=''> تست </a>",
                             @*template: kendo.template('@Html.ActionLink("#= FirstName #", "_SoftwareRequestEdit","SoftwareRequest",new {id = "tet"  }, class = "tet", null)')*@
                         },

                     { field: "UserName", title: "نام کاربری", editable: false },
                    {
                        command: [

                            { name: "edit", text: "ويرايش" },
                            {
                                name: "destroy", text: "حذف",
                                click: deleteItem

                            }  ,
                            //{ name: "destroy", text: "حذف" }
                        ],
                        title: "&nbsp;", width: "260px"
                    }

                    ],
                    editable: 
                         {
                        confirmation: "آیا مایل به حذف ردیف انتخابی هستید؟",
                        destroy: true, // whether or not to delete item when button is clicked
                        //mode: "popup", // options are "incell", "inline", and "popup"
                        //template: kendo.template($("#popupEditorTemplate").html()), // template to use for pop-up editing
                        update: true, // switch item to edit mode when clicked?
                        mode: "popup",
                        window: {
                            title: "مشخصات محصول"   // Localization for Edit in the popup window
                        }
                    },


                    messages: {
                        //editable: {
                        //    cancelDelete: "لغو",
                        //    confirmation: "آیا مایل به حذف این رکورد هستید؟"  ,
                        //    confirmDelete: "حذف",
                        //    click:_handleDelete
                        //},

                        commands: {
                            //create: "افزودن ردیف جدید",
                            //cancel: "لغو کلیه‌ی تغییرات",
                            //save: "ذخیره‌ی تمامی تغییرات",
                            //destroy: "حذف",

                            //edit: "ویرایش",
                            //update: "ثبت",
                            //canceledit: "لغو"
                        }
                    },

                    dataSource: {
                        schema: {
                            data: function (data) {
                                if (data != undefined &&
                                    data != undefined &&
                                    data.Data != undefined)
                                { return data.Data; }
                                else { return []; } //if null then return empty array
                            },
                            total: "Total",
                            model: {
                                id: "UserID",
                                fields: {
                                    id: { editable: false, type: "number" },
                                    FirstName: { type: "string" }
                                }
                            }
                        },

                        batch: false,
                        pageSize: 10,
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                        transport: {
                            read: {
                                url: "/User/Search", //specify the URL which data should return the records.
                                contentType: "application/json; charset=utf-8", // tells the web method to serialize JSON
                                type: "POST" //use HTTP POST or get
                            },
                            update: {
                                //  url:"@Url.Action("Update", "Home")", //specify the URL which should update the records. This is the Update method of the HomeController.
                                //  type: "POST"
                                url: function (list) {
                                    return "@Url.Action("Update", "Home")/" + list.UserID;
                                },
                                //contentType: 'application/json; charset=utf-8',
                                type: "post"
                            },
                            destroy: {
                                //url: crudServiceBaseUrl + "/Products/Destroy",
                                //dataType: "jsonp"
                            },
                            create: {
                                //url: crudServiceBaseUrl + "/Products/Create",
                                //dataType: "jsonp"
                            },
                            //parameter map function is used to map parameters before read operations
                            parameterMap: function (data, operation) {
                                if (data.models) { return JSON.stringify({ payReports: data.models }); }
                                else if (operation == "read") { //Page methods always need values for their parameters
                                    data = $.extend({ sort: null, filter: null }, data);
                                    return JSON.stringify(data);
                                }
                            }
                        },
                    },

                    ///برای ساختن ردیف در گرید
                    dataBound: function () {
                        var rows = this.items();
                        $(rows).each(function () {
                            var index = $(this).index() + 1;
                            var rowLabel = $(this).find(".row-number");
                            $(rowLabel).html(index);
                        });
                    },

                };

                function deleteItem(e) {
                    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
                    if (confirm('Are you sure you want to delete : ' + dataItem.name)) {
                        var grid = $("#grid").data("kendoGrid");
                        grid.dataSource.remove(dataItem);
                        grid.dataSource.sync();
                        grid.refresh();
                    }
                }
            });

        </script>
        <script>
            $(function () {
                   $('.tet').on("click", function () {
                    alert("JQuery Running!");
                });
            });
            function New() {
                alert("JQuery Running!");
            }


        </script>
        <script>
            // اين اطلاعات براي تهيه خروجي سمت سرور مناسب هستند
            function getCurrentGridFilters() {
                var dataSource = $("#report-grid").data("kendoGrid").dataSource;
                var gridState = {
                    page: dataSource.page(),
                    pageSize: dataSource.pageSize(),
                    sort: dataSource.sort(),
                    group: dataSource.group(),
                    filter: dataSource.filter()
                };
                return kendo.stringify(gridState);
            }
        function _handleDelete(event) {
            dataitem = grid.dataItem($(event.currentTarget).closest("tr"));
            kWindow.open();

        };
    </script>
    <script type="text/javascript">
        // جهت استفاده از فايل: kendo.culture.fa-IR.js
        kendo.culture("fa-IR");
    </script>
    <script id="toolbarTemplate" type="text/x-kendo-template">
        <a class="k-button" href="\#" onclick="alert('gridState: ' + getCurrentGridFilters());">نوار ابزار سفارشي</a>
    </script>


</body>

1 个答案:

答案 0 :(得分:0)

您可以使用自己的自定义对话框。请参阅示例here