<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>


        <telerik:RadGrid ID="grdCategory" runat="server" AutoGenerateColumns="false" CssClass="Gridheight4" OnNeedDataSource="grdCategory_NeedDataSource"
            OnBatchEditCommand="grdCategory_BatchEditCommand"
            Width="100%" AllowPaging="true" PageSize="10">
            <ClientSettings>
                <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                <KeyboardNavigationSettings AllowSubmitOnEnter="true" />
                <ClientEvents OnBatchEditOpening="onBatchEditOpening" OnBatchEditOpened="onBatchEditOpenned" />
            </ClientSettings>
            <MasterTableView DataKeyNames="Category" EditMode="Batch" HeaderStyle-Font-Size="8pt"
                HeaderStyle-Font-Bold="true" ItemStyle-Font-Size="8pt" PagerStyle-AlwaysVisible="true"
                CommandItemDisplay="Top" InsertItemDisplay="Top" BatchEditingSettings-EditType="Cell"
                BatchEditingSettings-OpenEditingEvent="Click">
                <CommandItemSettings ShowSaveChangesButton="true" ShowCancelChangesButton="true"
                    ShowRefreshButton="true" />
                <Columns>
                    <telerik:GridBoundColumn DataField="Category" UniqueName="Category" HeaderText="Category"
                        DataType="System.String" ItemStyle-CssClass="maximize" HeaderStyle-Width="250px" ItemStyle-Font-Size="8pt">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="Is_Active" UniqueName="Is_Active" HeaderText="Active"
                        HeaderStyle-Width="80px">
                        <ItemTemplate>
                            <telerik:RadSwitch runat="server" ID="CheckBox1" AutoPostBack="true" Enabled="false"
                                CssClass="elasticSwitch" Checked='<%# Eval("Is_Active") %>'>
                            </telerik:RadSwitch>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadSwitch runat="server" ID="CheckBox2" AutoPostBack="false"
                                CssClass="elasticSwitch">
                            </telerik:RadSwitch>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridCheckBoxColumn DataField="CCD_Only" UniqueName="CCD_Only" HeaderText="CCD Only"
                        HeaderTooltip="Show for CCD UMs Only.." DataType="System.Boolean">
                    </telerik:GridCheckBoxColumn>
                    <telerik:GridCheckBoxColumn DataField="MMS_Only" UniqueName="MMS_Only" HeaderText="MMS Only"
                        HeaderTooltip="Medication Management UMs Only.." DataType="System.Boolean">
                    </telerik:GridCheckBoxColumn>
                    <telerik:GridBoundColumn DataField="Comments" UniqueName="Comments"
                        HeaderText="Comments" DataType="System.String">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

    </form>
</body>
</html>

<script>

    function onBatchEditOpenned(sender, args) {

    }

    function onBatchEditOpening(sender, args) {
        args.get_tableView().get_dataItems();

        let cell = args.get_cell();
        let columnUniqueName = args.get_columnUniqueName();
        let item = args.get_row().control;
        let itemIndex = item.get_itemIndex();

        if (itemIndex > -1 && columnUniqueName === "Category") { // if itemIndex is -1 it means this is a new row
            debugger;
            args.set_cancel(true);
        }
    }
</script>
