예제 #1
0
        public static string PagingMgrGrid(this HtmlHelper htmlHelper, PagingMgr pagingMgr)
        {
            // Get the pagingState and pagingDirection
            var    route           = htmlHelper.ViewContext.RouteData;
            var    controllerName  = route.GetRequiredString("controller");
            var    actionName      = route.GetRequiredString("action");
            string pagingState     = htmlHelper.ViewContext.HttpContext.Request.Params["pagingState"];
            string pagingDirection = htmlHelper.ViewContext.HttpContext.Request.Params["pagingDirection"];

            PagingMgr.PagingDbCmdEnum pagingOption = string.IsNullOrWhiteSpace(pagingDirection) ?
                                                     PagingMgr.PagingDbCmdEnum.First :
                                                     (PagingMgr.PagingDbCmdEnum)Enum.Parse(typeof(PagingMgr.PagingDbCmdEnum), pagingDirection);

            if (!string.IsNullOrWhiteSpace(pagingState))
            {
                // Set the pagingState before getting the intended page
                pagingMgr.RestorePagingState(pagingState);

//                string initHtml = @"
//
//function showPage(action, data) {{
//    $.ajax({{
//        url: action,
//        type: ""get"",
//        format: ""html"",
//        cache: false,
//        data: data,
//        success: function (result) {{
//            // alert(result);
//            $(""#gridContainer"").html(result);
//        }},
//        error: function (xhr, status, error) {{
//
//            //?? CALL the client side error handling function which may be provided by the client
//
//            alert(xhr.responseText);
//            //?? showModalDialog(xhr.statusText, xhr.responseText);
//        }}
//    }});
//}}
//
//";
            }

            // Set the paging option and get the next page
            DataTable             pageTable = pagingMgr.GetPage(pagingOption);
            IEnumerable <dynamic> pageData  = DataTableToEnumerable(pageTable);

            // Realize the loop
            WebGrid webGrid = new WebGrid(pageData, rowsPerPage: pagingMgr.PageSize);

            // Get the new paging state for next and previous link
            string newPagingState = pagingMgr.GetPagingState();
            string html           =
                string.Format("<a href=\"/OurAdminWeb/Grid/TestSequences?pagingState={0}&pagingDirection={1}\">Previous</a>", newPagingState, "prev")
                + " | "
                + string.Format("<a href=\"/OurAdminWeb/Grid/TestSequences?pagingState={0}&pagingDirection={1}\">Next</a><br />", newPagingState, "next");

            return(html + webGrid.Table().ToHtmlString());
        }
예제 #2
0
        public static string ToHtmlString(this PagingMgr pagingMgr, Controller mvcController)
        {
            // Get the pagingState and pagingDirection
            var    route           = mvcController.RouteData;
            var    controllerName  = route.GetRequiredString("controller");
            var    actionName      = route.GetRequiredString("action");
            string pagingState     = mvcController.Request.Params["pagingState"];
            string pagingDirection = mvcController.Request.Params["pagingDirection"] ?? "first";

            // Set the pagingState before getting the intended page
            pagingMgr.RestorePagingState(pagingState);

            // Set the paging option and get the next page
            PagingMgr.PagingDbCmdEnum pagingOption = pagingDirection == "first" ? PagingMgr.PagingDbCmdEnum.First
                : pagingDirection == "next" ? PagingMgr.PagingDbCmdEnum.Next
                : pagingDirection == "prev" ? PagingMgr.PagingDbCmdEnum.Previous
                : PagingMgr.PagingDbCmdEnum.Last;
            DataTable             pageTable = pagingMgr.GetPage(pagingOption);
            IEnumerable <dynamic> pageData  = DataTableToEnumerable(pageTable);

            // Realize the loop
            WebGrid webGrid = new WebGrid(pageData, rowsPerPage: pagingMgr.PageSize);

            // Get the new paging state for next and previous link
            string newPagingState = pagingMgr.GetPagingState();
            string html           =
                string.Format("<a href=\"/OurAdminWeb/Grid/TestSequences?pagingState={0}&pagingDirection={1}\">Previous</a>", newPagingState, "prev")
                + " | "
                + string.Format("<a href=\"/OurAdminWeb/Grid/TestSequences?pagingState={0}&pagingDirection={1}\">Next</a><br />", newPagingState, "next");

            return(html + webGrid.Table().ToHtmlString());
        }
예제 #3
0
        public static IHtmlString ToHtmlString <T>(this PagingMgr pagingMgr, PagingMgr.PagingDbCmdEnum pagingDirection)
            where T : new()
        {
            IEnumerable <dynamic> pageData = (IEnumerable <dynamic>)pagingMgr.GetPage <T>(pagingDirection);
            WebGrid webGrid = new WebGrid(pageData);

            return(webGrid.Table());
        }
예제 #4
0
        public static IHtmlString GetTable(this WebGrid webGrid, string tableStyle = null, string headerStyle = null, string footerStyle = null, string rowStyle = null, string alternatingRowStyle = null, string selectedRowStyle = null, string caption = null, bool displayHeader = true, bool fillEmptyRows = false, string emptyRowCellValue = null, IEnumerable <WebGridColumn> columns = null, IEnumerable <string> exclusions = null, Func <dynamic, object> footer = null, dynamic parameters = null, string actionName = null)
        {
            IHtmlString htmlStr = webGrid.Table(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle,
                                                selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, columns, exclusions, footer);
            int pageNumber = webGrid.PageIndex + 1;

            string controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();

            if (string.IsNullOrEmpty(actionName))
            {
                actionName = "List";
            }

            var    html      = htmlStr.ToHtmlString();
            string strScript = "";
            string strTable  = html;

            //extract script tag from the document
            int scriptStartIndex = html.IndexOf("<script");

            if (scriptStartIndex > -1)
            {
                int scriptEndIndex = html.IndexOf("</script>") + 9;
                strScript = html.Substring(scriptStartIndex, scriptEndIndex - scriptStartIndex);
                strTable  = html.Substring(scriptEndIndex);
            }

            XDocument xdoc   = XDocument.Load(new StringReader(strTable));
            var       result = (from x in xdoc.Descendants(XName.Get("a"))
                                where x.Parent.Name == "th"
                                select x)
                               .ToArray();

            foreach (var item in result)
            {
                string href = item.Attribute(XName.Get("href")).Value;
                RouteValueDictionary parms = ParseParameters(href);
                parms.Add(webGrid.PageFieldName, pageNumber);
                parms = PopulateParameters(parms, parameters);

                //var actionNameDictionary = parms.SingleOrDefault(x => x.Key.ToLower().Equals("actionname"));
                //if (!actionNameDictionary.Equals(default(KeyValuePair<string, object>)))
                //{
                //    actionName = actionNameDictionary.Value.ToString();
                //    parms.Remove(actionNameDictionary.Key);
                //}

                UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var       url       = urlHelper.Action(actionName, controllerName, parms);

                item.Attribute(XName.Get("href")).Value = url;
            }

            string finalResult = xdoc.ToString();

            return(new MvcHtmlString(strScript + finalResult));
        }