<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="batch.aspx.cs" Inherits="Demo._3_Grid.batch" MasterPageFile="~/Site.Master" %>

<asp:Content runat="server" ContentPlaceHolderID="MainContent">

    <telerik:RadAjaxManager runat="server" ID="ajaxProxy" UpdatePanelsRenderMode="Inline"
        ClientEvents-OnRequestStart="requestStart">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="grid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="grid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

    <telerik:RadGrid runat="server" ID="grid" 
        EnableGroupsExpandAll="true"
        ItemType="Demo.Models.BoardGame"
        SelectMethod="GetGames" 
        UpdateMethod="SaveGame" 
        InsertMethod="AddGame">
        
        <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
            <Pdf PageHeight="11in" PageWidth="8.5in" DefaultFontFamily="Arial" PageTopMargin="0.5in" BorderStyle="Medium" BorderColor="#333" />
        </ExportSettings>

        <MasterTableView AutoGenerateColumns="false"
            GroupLoadMode="Client"
            EditMode="Batch" CommandItemDisplay="Top" DataKeyNames="ID">

            <CommandItemSettings ShowExportToPdfButton="true" />

            <BatchEditingSettings EditType="Row" 
                OpenEditingEvent="Click" />

            <Columns>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" ReadOnly="true" Visible="false"></telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Type" DataField="GameType">
                    <ItemTemplate><%#: Eval("GameType") %></ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="typeDDL">
                            <Items>
                                <telerik:RadComboBoxItem Text="Classic" Value="Classic" />
                                <telerik:RadComboBoxItem Text="Boardgame" Value="Boardgame" />
                                <telerik:RadComboBoxItem Text="Electric" Value="Electric" />
                                <telerik:RadComboBoxItem Text="Card" Value="Card" />
                                <telerik:RadComboBoxItem Text="Party" Value="Party"  />
                            </Items>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>

                <telerik:GridBoundColumn DataField="Name" HeaderText="Name"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="NumInStock" HeaderText="Num in Stock" ColumnEditorID="numericTextbox">
                </telerik:GridBoundColumn>
            </Columns>

            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldAlias="Type" FieldName="GameType" />
                    </SelectFields>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldAlias="GameType" FieldName="GameType" />
                    </GroupByFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>

        </MasterTableView>

    </telerik:RadGrid>

    <telerik:GridNumericColumnEditor runat="server" ID="numericTextbox">
        <NumericTextBox MinValue="0" MaxValue="100000">
            <NumberFormat DecimalDigits="0" />
        </NumericTextBox>
    </telerik:GridNumericColumnEditor>

        <a id="collapseAllButton" href="#">Collapse All</a> 


    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
        function requestStart(obj, args) {
            
            // Cancel AJAX interactions if we are requesting a PDF export
            if (args.get_eventTarget().indexOf("ExportToPdf") > 0) {
                args.set_enableAjax(false);
            }
            
        }

        var $grid = {
            id: "<%: grid.ClientID %>",
            obj: null
            };

        $().ready(function () {

            $grid.obj = $find($grid.id);

            $("#collapseAllButton").click(function () {
                $grid.obj.get_masterTableView().collapseAllGroups();
            })

        });
        </script>
    </telerik:RadCodeBlock>

</asp:Content>