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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%Html.Telerik().Grid(Model)
                     .Name("Orders")
                     .ToolBar(toolBar => toolBar.Template(() =>
                        {%>
                            Orders from:
                            <%=Html.Telerik().DatePicker().Name("StartDate") %>
                            to:
                            <%=Html.Telerik().DatePicker().Name("EndDate") %>
                            <a class="t-button" id="filter-btn">filter</a>
                        <%}))
                     .Columns(columns =>
                        {
                            columns.Bound(o => o.ID);
                            columns.Bound(o => o.CustomerName);
                            columns.Bound(o => o.EmployeeName);
                            columns.Bound(o => o.OrderDate).Format("{0:d}");
                        })
                     .DataBinding(dataBinding => dataBinding.Ajax().Select("Select","Home"))
                     .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding"))
                     .Pageable()
                     .Render();
    %>
    <script type="text/javascript">
        function dataBinding(args) {
            var startDate = $("#StartDate").data("tDatePicker").value();
            var endDate = $("#EndDate").data("tDatePicker").value();
            args.data = $.extend(args.data, {
                startDate: $.telerik.formatString("{0:d}", startDate),
                endDate: $.telerik.formatString("{0:d}", endDate)
            });
        }

        function attachFilter() {
            $("#filter-btn").click(function() {
                    $("#Orders").data("tGrid").rebind();
            });
        }
    </script>
    <%
      Html.Telerik().ScriptRegistrar()
          .OnDocumentReady("attachFilter();");%>
</asp:Content>
