ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Measure/Units.cshtml
@{
    //page title
    ViewBag.Title = T("Admin.Configuration.Measures.Units").Text;
}

<div class="row">
    <div class="col-md-12">
        <div class="x_panel light form-fit">
            <div class="x_title">
                <div class="caption level-caption">
                    <i class="fa fa-wrench"></i>
                    @T("Admin.Configuration.Measures.Units")
                </div>
            </div>
            <div class="x_content form">
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="x_content">
                            <div id="measureunit-grid"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function() {
        $("#measureunit-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("Units", "Measure"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    create: {
                        url: "@Html.Raw(Url.Action("UnitAdd", "Measure"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    update: {
                        url: "@Html.Raw(Url.Action("UnitUpdate", "Measure"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    destroy: {
                        url: "@Html.Raw(Url.Action("UnitDelete", "Measure"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            Name: { editable: true, type: "string" },
                            DisplayOrder: { editable: true, type: "number" },
                            Id: { editable: false, type: "string" }
                        }
                    }
                },
                requestEnd: function(e) {
                    if (e.type == "create" || e.type == "update") {
                        this.read();
                    }
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                numeric: false,
                previousNext: false,
                info: false
            },
            toolbar: [{ name: "create", text: "@T("Admin.Common.AddNewRecord")" }],
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [
            {
                field: "Name",
                title: "@T("Admin.Configuration.Measures.Units.Fields.Name")",
                width: 300
            }, {
                field: "DisplayOrder",
                title: "@T("Admin.Configuration.Measures.Weights.Fields.DisplayOrder")",
                //integer format
                format: "{0:0}",
                width: 100
            },{
                command: [
                {
                    name: "edit",
                    text: {
                        edit: "@T("Admin.Common.Edit")",
                        update: "@T("Admin.Common.Update")",
                        cancel: "@T("Admin.Common.Cancel")"
                    }
                }, {
                    name: "destroy",
                    text: "@T("Admin.Common.Delete")"
                        }
                    ],
                    width: 200
                }
            ]
        });
    });
</script>