<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<GridExcelExport.Models.Order>>" %>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    
    <%= Html.ActionLink("Export to Excel", "Export", new { page = 1, orderBy = "~", filter = "~"}, new { id = "exportLink" }) %>

    <script type="text/javascript">
        function onDataBound() {
            var grid = $(this).data('tGrid');
            var $exportLink = $('#exportLink');
            var href = $exportLink.attr('href');
            href = href.replace(/page=([^&]*)/, 'page=' + grid.currentPage);
            href = href.replace(/orderBy=([^&]*)/, 'orderBy=' + (grid.orderBy || '~'));
            href = href.replace(/filter=(.*)/, 'filter=' + (grid.filterBy || '~'));
            $exportLink.attr('href', href);
        }
    </script>
        
    <%= Html.Telerik().Grid(Model)
            .Name("Grid")
            .Columns(columns =>
            {
                columns.Bound(o => o.OrderID);
                columns.Bound(o => o.ShipAddress);
                columns.Bound(o => o.CustomerID);
                columns.Bound(o => o.ShipCountry);
                columns.Bound(o => o.OrderDate);
            })
            .Pageable()
            .Sortable()
            .Filterable()
            .DataBinding(dataBinding => dataBinding
                .Ajax()
                    .Select("IndexAjax", "Home"))
            .ClientEvents(events => events.OnDataBound("onDataBound"))
    %>

</asp:Content>
