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

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Namespace="CustomColumns" TagPrefix="ac" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
        <!--
            function pageLoad(sender, eventArgs)
            {
                $get("<%= Panel1.ClientID %>").innerHTML = "";

                var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();

                $find("<%= RadAjaxLoadingPanel1.ClientID %>").show("<%= RadGrid1.ClientID %>");

                PageMethods.GetData(0, tableView.get_pageSize(),
                tableView.get_sortExpressions().toString(), tableView.get_filterExpressions().toList(),
                    updateGrid);

                PageMethods.GetCount(tableView.get_filterExpressions().toList(), updateVirtualItemCount);
            }

            function RadGrid1_Command(sender, args)
            {
                $get("<%= Panel1.ClientID %>").innerHTML = String.format("<b>RadGrid1_Command</b><br />CommandName : {0}, CommandArgument : {1} <br /><br />", args.get_commandName(), args.get_commandArgument());

                args.set_cancel(true);

                var pageSize = sender.get_masterTableView().get_pageSize();

                var sortExpressions = sender.get_masterTableView().get_sortExpressions();
                var filterExpressions = sender.get_masterTableView().get_filterExpressions();

                var currentPageIndex = sender.get_masterTableView().get_currentPageIndex();

                if (args.get_commandName() == "Filter")
                    currentPageIndex = 0;


                var sortExpressionsAsSQL = sortExpressions.toString();
                var filterExpressionsAsSQL = filterExpressions.toString();

                $find("<%= RadAjaxLoadingPanel1.ClientID %>").show("<%= RadGrid1.ClientID %>");

                PageMethods.GetData(currentPageIndex * pageSize, pageSize, sortExpressionsAsSQL, filterExpressions.toList(), updateGrid);

                if (args.get_commandName() == "Filter")
                {
                    PageMethods.GetCount(filterExpressions.toList(), updateVirtualItemCount);
                }
            }

            function updateGrid(result)
            {
                var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                tableView.set_dataSource([]);
                tableView.dataBind();

                $find("<%= RadAjaxLoadingPanel1.ClientID %>").hide("<%= RadGrid1.ClientID %>");
            }

            function updateVirtualItemCount(result)
            {
                var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                tableView.set_virtualItemCount(result);
            }

            function toggleAllowMultiColumnSorting(sender, e)
            {
                var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                tableView.set_allowMultiColumnSorting(sender.checked);
            }

            function RadGrid1_RowDataBound(sender, args)
            {

            }

            function rowDropped(sender, args)
            {

            }
        -->
        </script>
    </telerik:RadCodeBlock>
    <!-- content start -->
    <asp:CheckBox ID="CheckBox1" Text="Allow multi column sorting" Checked="true" runat="server"
        onclick="toggleAllowMultiColumnSorting(this, event);" />
    <br />
    <br />
    <telerik:RadGrid ID="RadGrid1" EnableViewState="false" runat="server" PageSize="10"
        AllowPaging="true" AllowSorting="True" AllowFilteringByColumn="true" GridLines="None">
        <ItemStyle Wrap="false" />
        <MasterTableView AllowMultiColumnSorting="true" TableLayout="Fixed">
            <Columns>
                <telerik:GridBoundColumn DataField="EmployeeID">
                </telerik:GridBoundColumn>
                <telerik:GridHyperLinkColumn NavigateUrl="http://www.eparhia-lovech.com" DataTextField="FirstName"
                    HeaderText="FirstName" />
                <ac:LinkColumn NavigateUrl="http://www.eparhia-lovech.com" DataTextField="FirstName"
                    HeaderText="FirstName" />
            </Columns>
        </MasterTableView>
        <PagerStyle AlwaysVisible="true" Mode="NumericPages" />
        <ClientSettings AllowRowsDragDrop="true" Selecting-AllowRowSelect="true">
            <ClientEvents OnCommand="RadGrid1_Command" OnRowDataBound="RadGrid1_RowDataBound"
                OnRowDropped="rowDropped" />
        </ClientSettings>
    </telerik:RadGrid>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <br />
    <br />
    Events:
    <asp:Panel ID="Panel1" Style="height: 200px; overflow: auto; padding: 15px;" CssClass="module"
        runat="server">
    </asp:Panel>
    </form>
</body>
</html>
