Beispiel #1
0
        /// <summary>
        /// Gets the HTML for a table with a pager.
        /// </summary>
        /// <param name="tableStyle">Table class for styling.</param>
        /// <param name="headerStyle">Header row class for styling.</param>
        /// <param name="footerStyle">Footer row class for styling.</param>
        /// <param name="rowStyle">Row class for styling (odd rows only).</param>
        /// <param name="alternatingRowStyle">Row class for styling (even rows only).</param>
        /// <param name="selectedRowStyle">Selected row class for styling.</param>
        /// <param name="displayHeader">Whether the header row should be displayed.</param>
        /// <param name="caption">The string displayed as the table caption</param>
        /// <param name="fillEmptyRows">Whether the table can add empty rows to ensure the rowsPerPage row count.</param>
        /// <param name="emptyRowCellValue">Value used to populate empty rows. This property is only used when <paramref name="fillEmptyRows"/> is set</param>
        /// <param name="columns">Column model for customizing column rendering.</param>
        /// <param name="exclusions">Columns to exclude when auto-populating columns.</param>
        /// <param name="mode">Modes for pager rendering.</param>
        /// <param name="firstText">Text for link to first page.</param>
        /// <param name="previousText">Text for link to previous page.</param>
        /// <param name="nextText">Text for link to next page.</param>
        /// <param name="lastText">Text for link to last page.</param>
        /// <param name="numericLinksCount">Number of numeric links that should display.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        public IHtmlString GetHtml(
            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,
            WebGridPagerModes mode              = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
            string firstText                    = null,
            string previousText                 = null,
            string nextText                     = null,
            string lastText                     = null,
            int numericLinksCount               = 5,
            object htmlAttributes               = null)
        {
            Func <dynamic, object> footer = null;

            if (_canPage && (PageCount > 1))
            {
                footer = item => Pager(mode, firstText, previousText, nextText, lastText, numericLinksCount, explicitlyCalled: false);
            }

            return(Table(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader,
                         fillEmptyRows, emptyRowCellValue, columns, exclusions, footer: footer,
                         htmlAttributes: htmlAttributes));
        }
 private static bool ModeEnabled(
     WebGridPagerModes mode,
     WebGridPagerModes modeCheck
     )
 {
     return((mode & modeCheck) == modeCheck);
 }
        public static IHtmlString GetTableWithPager(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,
                                                    WebGridPagerModes mode              = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
                                                    string firstText      = null,
                                                    string previousText   = null,
                                                    string nextText       = null,
                                                    string lastText       = null,
                                                    int numericLinksCount = 5,
                                                    object parameters     = null,
                                                    string actionName     = null,
                                                    int?currerntPageIndex = null)
        {
            //get table with pager inside the footer
            IHtmlString strTable = GetTable(webGrid, tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle,
                                            selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, columns, exclusions
                                            , x => PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, parameters, actionName, currerntPageIndex ?? webGrid.PageIndex),
                                            parameters, actionName);

            //string
            return(strTable);
        }
Beispiel #4
0
 /// <summary>
 /// Gets the HTML for a pager.
 /// </summary>
 /// <param name="mode">Modes for pager rendering.</param>
 /// <param name="firstText">Text for link to first page.</param>
 /// <param name="previousText">Text for link to previous page.</param>
 /// <param name="nextText">Text for link to next page.</param>
 /// <param name="lastText">Text for link to last page.</param>
 /// <param name="numericLinksCount">Number of numeric links that should display.</param>
 public HelperResult Pager(
     WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
     string firstText       = null,
     string previousText    = null,
     string nextText        = null,
     string lastText        = null,
     int numericLinksCount  = 5)
 {
     return(Pager(mode, firstText, previousText, nextText, lastText, numericLinksCount, explicitlyCalled: true));
 }
 public static HelperResult PagerList(
     this WebGrid webGrid,
     WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
     string firstText = null,
     string previousText = null,
     string nextText = null,
     string lastText = null,
     int numericLinksCount = 5)
 {
     return PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, explicitlyCalled: true);
 }
Beispiel #6
0
 public static HelperResult PagerList(
     this WebGrid webGrid,
     WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
     string firstText       = null,
     string previousText    = null,
     string nextText        = null,
     string lastText        = null,
     int numericLinksCount  = 5, bool isHttpPost = false)
 {
     return(PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, isHttpPost, explicitlyCalled: true));
 }
 public static HelperResult PagerList(
     this WebGrid webGrid,
     WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
     string firstText       = null,
     string previousText    = null,
     string nextText        = null,
     string lastText        = null,
     int numericLinksCount  = 5,
     string paginationStyle = null)
 {
     return(PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, paginationStyle, explicitlyCalled: true));
 }
Beispiel #8
0
        public static IHtmlString GetHtmlWithExtraHeader(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,
                                                         WebGridPagerModes mode   = WebGridPagerModes.All, string firstText   = null, string previousText = null, string nextText = null,
                                                         string lastText          = null, int numericLinksCount = 5, object htmlAttributes = null, string checkBoxValue = "ID",
                                                         IEnumerable <ExtraHeader> extraHeaders = null, bool displayInChinese = false, bool hideIdColumn = false, string hideColumnName = null)
        {
            StringBuilder sb = new StringBuilder();

            if (extraHeaders != null)
            {
                var headerlevels = extraHeaders.Select(h => h.HeaderLevel).Distinct().OrderBy(h => h);

                sb.Append("<thead>");
                foreach (var headerlevel in headerlevels)
                {
                    sb.Append("<tr class='hr'>");
                    sb.Append("<th></th>"); //the first column is always the row name column.
                    foreach (var header in extraHeaders.Where(h => h.HeaderLevel == headerlevel))
                    {
                        sb.Append(header.HeaderColumnSpan > 0 ? "<th colspan='" + header.HeaderColumnSpan + "' " : "<th ");
                        sb.Append(string.IsNullOrEmpty(header.HeaderStyle) ? string.Empty : "style = " + header.HeaderStyle);
                        sb.Append(">");
                        sb.Append(header.HeaderText);
                        sb.Append("</th>");
                    }
                    sb.Append("</tr>");
                }
            }

            var    html = webGrid.GetHtml(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, columns, exclusions, mode, firstText, previousText, nextText, lastText, numericLinksCount, htmlAttributes);
            string htmlToReplaceThead = html.ToString();

            //string htmlAfterReplaceThead = htmlToReplaceThead.Replace("</thead>\r\n    <tbody>\r\n", "");
            //string htmlBeforeReplaceTh = htmlAfterReplaceThead.Replace("<th", "<td");
            //string htmlAfterReplaceTh = htmlBeforeReplaceTh.Replace("</th>", "</td>");

            if (!hideIdColumn)
            {
                return(MvcHtmlString.Create(htmlToReplaceThead.Replace("<thead>", sb.ToString())));// Replace thead with extra header
            }
            if (string.IsNullOrEmpty(hideColumnName))
            {
                hideColumnName = "ID";
            }
            string htmlToReplaceIdColumn  = htmlToReplaceThead.Replace("<th scope=\"col\">\r\n" + hideColumnName + "            </th>\r\n", "");
            string stringToSelectFirstRow = htmlToReplaceIdColumn.Replace("<thead>", sb.ToString());

            return(MvcHtmlString.Create(stringToSelectFirstRow.Replace("<tbody>\r\n        <tr>", "<tbody>\r\n        <tr class='SelectedRow'>")));// Replace thead with extra header
        }
Beispiel #9
0
        public static IHtmlString GetHtmlWithSelectAllCheckBox(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, WebGridPagerModes mode = WebGridPagerModes.All, string firstText = null, string previousText = null, string nextText = null, string lastText = null, int numericLinksCount = 5, object htmlAttributes = null, string checkBoxValue = "ID", int checkBoxColumnPosition = 0, bool defaultCheckedState = false, System.Web.Mvc.HtmlHelper helper = null)
        {
            var newVisibleCheckBoxColumn = AddVisibleCheckBoxColumnForCheckedItems(webGrid, checkBoxValue, defaultCheckedState);

            var newInvisibleCheckBoxColumn = AddInvisibleCheckboxColumnForUncheckedItems(webGrid, checkBoxValue, !defaultCheckedState);

            var newColumns = AddColumnsToGrid(columns, checkBoxColumnPosition, newVisibleCheckBoxColumn, newInvisibleCheckBoxColumn);

            var script = @"<script type=""text/javascript"">
                $(document).ready(function(){
                    $('.grid td:nth-child(' + " + checkBoxColumnPosition + 2 + @" + '),th:nth-child( ' + " + checkBoxColumnPosition + 2 + @" + ')').hide();
                    $('#allCheckBox').click(function () {
                        var isChecked = $(this).attr('checked');
                        if (isChecked){
                            $('.singleHiddenCheckBox').attr('checked', 'checked');
                        }
                        else{
                            $('.singleHiddenCheckBox').removeAttr('checked');
                        }
                        if (isChecked){
                            $('.singleCheckBox').removeAttr('checked');
                        }
                        else{
                            $('.singleCheckBox').attr('checked', 'checked');
                        }
                        $('.singleCheckBox').closest('tr').addClass(isChecked  ? 'selected-row': 'not-selected-row');
                        $('.singleCheckBox').closest('tr').removeClass(isChecked  ? 'not-selected-row': 'selected-row');
                    });
                    $('.singleCheckBox').click(function () {
                        var isChecked = $(this).attr('checked');
                        var id = $(this).attr('value');
                        if (isChecked){
                            $('#unChecked' + id).removeAttr('checked');
                        }
                        else{
                            $('#unChecked' + id).attr('checked', 'checked');
                        }
                        $(this).closest('tr').addClass(isChecked  ? 'selected-row': 'not-selected-row');
                        $(this).closest('tr').removeClass(isChecked  ? 'not-selected-row': 'selected-row');
                        if(isChecked && $('.singleCheckBox').length == $('.selected-row').length)
                                $('#allCheckBox').attr('checked','checked');
                        else
                            $('#allCheckBox').removeAttr('checked');
                    });
                });
            </script>";

            var html = string.Format("{0}{1}{2}", script, Environment.NewLine, webGrid.GetHtml(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, newColumns, exclusions, mode, firstText, previousText, nextText, lastText, numericLinksCount, htmlAttributes));
            return MvcHtmlString.Create(html.ToString().Replace("{}", "<input type=\"checkbox\" id=\"allCheckBox\" " + (defaultCheckedState ? "checked=\"checked\" " : string.Empty) + "/>") + (helper == null ? script : string.Empty));
        }
Beispiel #10
0
        /// <summary>
        /// Get the HTML string for a given grid. (render)
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="columns"></param>
        /// <param name="title">grid header</param>
        /// <param name="_htmlAttributes"></param>
        /// <param name="tableStyle"></param>
        /// <param name="headerStyle"></param>
        /// <param name="footerStyle"></param>
        /// <param name="alternatingRowStyle"></param>
        /// <param name="fillEmptyRows"></param>
        /// <param name="emptyRowsCellValue"></param>
        /// <param name="gridWrapperDivID">This identifies the area to fill after an ajax operation</param>
        /// <returns></returns>
        public static MvcHtmlString GetHtmlCustom(this WebGrid grid,
                                                  WebGridColumn[] columns,
                                                  string title                = null,
                                                  object _htmlAttributes      = null,
                                                  string tableStyle           = "webgrid",
                                                  string headerStyle          = "webgrid-header",
                                                  string footerStyle          = "webgrid-header grid-footer",
                                                  string alternatingRowStyle  = "webgrid-alternating-rows",
                                                  bool fillEmptyRows          = false,
                                                  string emptyRowsCellValue   = null,
                                                  string gridWrapperDivID     = "grid",
                                                  bool scrollable             = false, //if you turn off paging, you probably want to make the grid scrollable instead
                                                  WebGridPagerModes pagerMode = WebGridPagerModes.Numeric | WebGridPagerModes.NextPrevious,
                                                  int pagerLinksCount         = PAGER_LINKS)
        {
            TagBuilder wrapper = new TagBuilder("div");

            wrapper.AddCssClass("webgrid-wrapper");
            TagBuilder titleWrapper = new TagBuilder("div");

            titleWrapper.AddCssClass("webgrid-title");
            titleWrapper.SetInnerText(title);
            wrapper.InnerHtml += titleWrapper.ToString();

            TagBuilder gridWrapper = new TagBuilder("div");

            gridWrapper.Attributes.Add("id", gridWrapperDivID);     //this is where ajax ops will rerender returned content

            //make the wrapper div scrollable if paging is turned off
            if (scrollable)
            {
                gridWrapper.AddCssClass("scrollable");
            }

            gridWrapper.InnerHtml += grid.GetHtml(
                htmlAttributes: (_htmlAttributes ?? new { id = "webGrid" }),
                tableStyle: tableStyle,
                headerStyle: headerStyle,
                footerStyle: footerStyle,
                alternatingRowStyle: alternatingRowStyle,
                fillEmptyRows: fillEmptyRows,
                columns: columns,
                mode: pagerMode,
                numericLinksCount: pagerLinksCount).ToString();

            wrapper.InnerHtml += gridWrapper.ToString();

            return(MvcHtmlString.Create(wrapper.ToString()));
        }
 public static HelperResult PagerList(
     this WebGrid webGrid,
     WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
     string firstText       = null,
     string previousText    = null,
     string nextText        = null,
     string lastText        = null,
     int numericLinksCount  = 5)
 {
     if (webGrid.TotalRowCount > 0)
     {
         return(PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, explicitlyCalled: true));
     }
     return(null);
 }
Beispiel #12
0
        /// <param name="mode">Modes for pager rendering.</param>
        /// <param name="firstText">Text for link to first page.</param>
        /// <param name="previousText">Text for link to previous page.</param>
        /// <param name="nextText">Text for link to next page.</param>
        /// <param name="lastText">Text for link to last page.</param>
        /// <param name="numericLinksCount">Number of numeric links that should display.</param>
        /// <param name="explicitlyCalled">The Pager can be explicitly called by the public API or is called by the WebGrid when no footer is provided.
        /// In the explicit scenario, we would need to render a container for the pager to allow identifying the pager links.
        /// In the implicit scenario, the grid table would be the container.
        /// </param>
        private HelperResult Pager(
            WebGridPagerModes mode,
            string firstText,
            string previousText,
            string nextText,
            string lastText,
            int numericLinksCount,
            bool explicitlyCalled)
        {
            if (!_canPage)
            {
                throw new NotSupportedException(HelpersResources.WebGrid_NotSupportedIfPagingIsDisabled);
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (firstText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "FirstLast"), "firstText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (previousText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "NextPrevious"), "previousText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (nextText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "NextPrevious"), "nextText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (lastText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "FirstLast"), "lastText");
            }
            if (numericLinksCount < 0)
            {
                throw new ArgumentOutOfRangeException("numericLinksCount",
                                                      String.Format(CultureInfo.CurrentCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }

            return(WebGridRenderer.Pager(this, HttpContext, mode: mode, firstText: firstText, previousText: previousText, nextText: nextText, lastText: lastText,
                                         numericLinksCount: numericLinksCount, renderAjaxContainer: explicitlyCalled));
        }
Beispiel #13
0
        public HelperResult Pager(
            WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
            string firstText = null,
            string previousText = null,
            string nextText = null,
            string lastText = null,
            int numericLinksCount = 5) {

            if (!_canPage) {
                throw new NotSupportedException(HelpersResources.WebGrid_NotSupportedIfPagingIsDisabled);
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (firstText != null)) {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                    HelpersResources.WebGrid_PagerModeMustBeEnabled, "FirstLast"), "firstText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (previousText != null)) {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                    HelpersResources.WebGrid_PagerModeMustBeEnabled, "NextPrevious"), "previousText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (nextText != null)) {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                    HelpersResources.WebGrid_PagerModeMustBeEnabled, "NextPrevious"), "nextText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (lastText != null)) {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                    HelpersResources.WebGrid_PagerModeMustBeEnabled, "FirstLast"), "lastText");
            }
            if (numericLinksCount < 0) {
                throw new ArgumentOutOfRangeException("numericLinksCount",
                    String.Format(CultureInfo.CurrentCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }

            int currentPage = PageIndex;
            int totalPages = PageCount;
            int lastPage = totalPages - 1;

            return new HelperResult(tw => {
                tw.Write(GetJQueryCheckScriptHtml());

                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && currentPage > 1) {
                    if (String.IsNullOrEmpty(firstText)) {
                        firstText = "<<";
                    }
                    tw.Write(GetPageLinkHtml(0, firstText));
                    tw.Write(" ");
                }
                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && currentPage > 0) {
                    if (String.IsNullOrEmpty(previousText)) {
                        previousText = "<";
                    }
                    tw.Write(GetPageLinkHtml(currentPage - 1, previousText));
                    tw.Write(" ");
                }

                if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1)) {
                    int last = currentPage + (numericLinksCount / 2);
                    int first = last - numericLinksCount + 1;
                    if (last > lastPage) {
                        first -= last - lastPage;
                        last = lastPage;
                    }
                    if (first < 0) {
                        last = Math.Min(last + (0 - first), lastPage);
                        first = 0;
                    }
                    for (int i = first; i <= last; i++) {
                        if (i == currentPage) {
                            tw.Write((i + 1).ToString(CultureInfo.InvariantCulture));
                        }
                        else {
                            tw.Write(GetPageLinkHtml(i));
                        }
                        tw.Write(" ");
                    }
                }

                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (currentPage < lastPage)) {
                    if (String.IsNullOrEmpty(nextText)) {
                        nextText = ">";
                    }
                    tw.Write(GetPageLinkHtml(currentPage + 1, nextText));
                    tw.Write(" ");
                }
                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && (currentPage < lastPage - 1)) {
                    if (String.IsNullOrEmpty(lastText)) {
                        lastText = ">>";
                    }
                    tw.Write(GetPageLinkHtml(lastPage, lastText));
                }
            });
        }
Beispiel #14
0
        /// <summary>
        /// Gets the HTML for a table with a pager.
        /// </summary>
        /// <param name="tableStyle">Table class for styling.</param>
        /// <param name="headerStyle">Header row class for styling.</param>
        /// <param name="footerStyle">Footer row class for styling.</param>
        /// <param name="rowStyle">Row class for styling (odd rows only).</param>
        /// <param name="alternatingRowStyle">Row class for styling (even rows only).</param>
        /// <param name="selectedRowStyle">Selected row class for styling.</param>
        /// <param name="displayHeader">Whether the header row should be displayed.</param>
        /// <param name="caption">The string displayed as the table caption</param>
        /// <param name="fillEmptyRows">Whether the table can add empty rows to ensure the rowsPerPage row count.</param>
        /// <param name="emptyRowCellValue">Value used to populate empty rows. This property is only used when <see cref="fillEmptyRows"/> is set</param>
        /// <param name="columns">Column model for customizing column rendering.</param>
        /// <param name="exclusions">Columns to exclude when auto-populating columns.</param>
        /// <param name="mode">Modes for pager rendering.</param>
        /// <param name="firstText">Text for link to first page.</param>
        /// <param name="previousText">Text for link to previous page.</param>
        /// <param name="nextText">Text for link to next page.</param>
        /// <param name="lastText">Text for link to last page.</param>
        /// <param name="numericLinksCount">Number of numeric links that should display.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        public IHtmlString GetHtml(
            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,
            WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
            string firstText = null,
            string previousText = null,
            string nextText = null,
            string lastText = null,
            int numericLinksCount = 5,
            object htmlAttributes = null) {

            Func<dynamic, object> footer = null;
            if (_canPage && (PageCount > 1)) {
                footer = item => Pager(mode, firstText, previousText, nextText, lastText, numericLinksCount);
            }

            return Table(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader,
                fillEmptyRows, emptyRowCellValue, columns, exclusions, footer: footer,
                htmlAttributes: htmlAttributes);
        }
    private static HelperResult PagerList(
        WebGrid webGrid,
        WebGridPagerModes mode,
        string firstText,
        string previousText,
        string nextText,
        string lastText,
        int numericLinksCount,
        bool explicitlyCalled)
    {
        int currentPage = webGrid.PageIndex;
        int totalPages = webGrid.PageCount;
        int lastPage = totalPages - 1;

        var ul = new TagBuilder("ul");
        var li = new List<TagBuilder>();

        if (webGrid.TotalRowCount <= webGrid.PageCount)
        {
            return new HelperResult(writer =>
            {
                writer.Write(string.Empty);
            });
        }

        if (ModeEnabled(mode, WebGridPagerModes.FirstLast))
        {
            if (String.IsNullOrEmpty(firstText))
            {
                firstText = "Перв.";
            }

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(0), firstText)
            };

            if (currentPage == 0)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);

        }

        if (ModeEnabled(mode, WebGridPagerModes.NextPrevious))
        {
            if (String.IsNullOrEmpty(previousText))
            {
                previousText = "Пред.";
            }

            int page = currentPage == 0 ? 0 : currentPage - 1;

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), previousText)
            };

            if (currentPage == 0)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);

        }

        if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
        {
            int last = currentPage + (numericLinksCount / 2);
            int first = last - numericLinksCount + 1;
            if (last > lastPage)
            {
                first -= last - lastPage;
                last = lastPage;
            }
            if (first < 0)
            {
                last = Math.Min(last + (0 - first), lastPage);
                first = 0;
            }
            for (int i = first; i <= last; i++)
            {

                var pageText = (i + 1).ToString(CultureInfo.InvariantCulture);
                var part = new TagBuilder("li")
                {
                    InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(i), pageText)
                };

                if (i == currentPage)
                {
                    part.MergeAttribute("class", "active");
                }

                li.Add(part);

            }
        }

        if (ModeEnabled(mode, WebGridPagerModes.NextPrevious))
        {
            if (String.IsNullOrEmpty(nextText))
            {
                nextText = "След.";
            }

            int page = currentPage == lastPage ? lastPage : currentPage + 1;

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), nextText)
            };

            if (currentPage == lastPage)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);

        }

        if (ModeEnabled(mode, WebGridPagerModes.FirstLast))
        {
            if (String.IsNullOrEmpty(lastText))
            {
                lastText = "Посл.";
            }

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText)
            };

            if (currentPage == lastPage)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);

        }

        ul.InnerHtml = string.Join("", li);

        var html = "";
        if (explicitlyCalled && true)
        {
            var span = new TagBuilder("span");
            span.MergeAttribute("data-swhgajax", "true");
            span.MergeAttribute("data-swhgcontainer", webGrid.AjaxUpdateContainerId);
            span.MergeAttribute("data-swhgcallback", webGrid.AjaxUpdateCallback);

            span.InnerHtml = ul.ToString();
            html = span.ToString();

        }
        else
        {
            html = ul.ToString();
        }

        return new HelperResult(writer =>
        {
            writer.Write(html);
        });
    }
Beispiel #16
0
        public static IHtmlString GetHtmlWithSelectAllCheckBox(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, WebGridPagerModes mode = WebGridPagerModes.All,
    string firstText = null, string previousText = null, string nextText = null,
    string lastText = null, int numericLinksCount = 5, object htmlAttributes = null,
    string checkBoxValue = "ContextIndex")
        {
            var newColumn = webGrid.Column(header: "{}",
            format: item => new HelperResult(writer =>
            {
                writer.Write("<input class=\"singleCheckBox\" name=\"selectedIndex\" value=\""
                + item.Value.GetType().GetProperty(checkBoxValue).GetValue(item.Value, null).ToString()
                + "\" type=\"checkbox\" />"
                );
            }));

            var newColumns = columns.ToList();
            newColumns.Insert(0, newColumn);

            var script = @"<script>

                if (typeof jQuery == 'undefined')
                {
                    document.write(
                        unescape(
                        ""%3Cscript src='../Scripts/jquery.min.js'%3E%3C/script%3E""
                        )
                     );
                }

                (function(){

                    window.setTimeout(function() { initializeCheckBoxes();  }, 1000);
                    function initializeCheckBoxes(){

                        $(function () {

                            $('#allCheckBox').live('click',function () {

                                var isChecked = $(this).attr('checked');
                                $('.singleCheckBox').attr('checked', isChecked  ? true: false);
                                $('.singleCheckBox').closest('tr').addClass(isChecked  ? 'selected-row': 'not-selected-row');
                                $('.singleCheckBox').closest('tr').removeClass(isChecked  ? 'not-selected-row': 'selected-row');

                            });

                            $('.singleCheckBox').live('click',function () {

                                var isChecked = $(this).attr('checked');
                                $(this).closest('tr').addClass(isChecked  ? 'selected-row': 'not-selected-row');
                                $(this).closest('tr').removeClass(isChecked  ? 'not-selected-row': 'selected-row');
                                if(isChecked && $('.singleCheckBox').length == $('.selected-row').length)
                                     $('#allCheckBox').attr('checked',true);
                                else
                                    $('#allCheckBox').attr('checked',false);

                            });

                        });
                    }

                })();
            </script>";

            var html = webGrid.GetHtml(tableStyle, headerStyle, footerStyle, rowStyle,
                                    alternatingRowStyle, selectedRowStyle, caption,
                                    displayHeader, fillEmptyRows, emptyRowCellValue,
                                    newColumns, exclusions, mode, firstText,
                                    previousText, nextText, lastText,
                                    numericLinksCount, htmlAttributes
                                    );

            return MvcHtmlString.Create(html.ToString().Replace("{}",
                                        "<input type='checkbox' id='allCheckBox'/>") + script);
        }
        public static HelperResult Pager(
            WebGrid webGrid,
            HttpContextBase httpContext,
            WebGridPagerModes mode,
            string firstText,
            string previousText,
            string nextText,
            string lastText,
            int numericLinksCount,
            bool renderAjaxContainer)
        {
            return(new HelperResult(__razor_helper_writer =>
            {
                int currentPage = webGrid.PageIndex;
                int totalPages = webGrid.PageCount;
                int lastPage = totalPages - 1;

                WriteTo(@__razor_helper_writer, GridInitScript(webGrid, httpContext));

                if (renderAjaxContainer && webGrid.IsAjaxEnabled)
                {
                    WriteLiteralTo(@__razor_helper_writer, "        ");

                    WriteLiteralTo(@__razor_helper_writer, "<span data-swhgajax=\"true\" data-swhgcontainer=\"");

                    WriteTo(@__razor_helper_writer, webGrid.AjaxUpdateContainerId);

                    WriteLiteralTo(@__razor_helper_writer, "\" data-swhgcallback=\"");

                    WriteTo(@__razor_helper_writer, webGrid.AjaxUpdateCallback);

                    WriteLiteralTo(@__razor_helper_writer, "\">\r\n");
                }

                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && currentPage > 1)
                {
                    if (String.IsNullOrEmpty(firstText))
                    {
                        firstText = "<<";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(0), firstText));

                    WriteTo(@__razor_helper_writer, Raw(" "));
                }

                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && currentPage > 0)
                {
                    if (String.IsNullOrEmpty(previousText))
                    {
                        previousText = "<";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(currentPage - 1), previousText));

                    WriteTo(@__razor_helper_writer, Raw(" "));
                }

                if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
                {
                    int last = currentPage + (numericLinksCount / 2);
                    int first = last - numericLinksCount + 1;
                    if (last > lastPage)
                    {
                        first -= last - lastPage;
                        last = lastPage;
                    }
                    if (first < 0)
                    {
                        last = Math.Min(last + (0 - first), lastPage);
                        first = 0;
                    }
                    for (int i = first; i <= last; i++)
                    {
                        var pageText = (i + 1).ToString(CultureInfo.InvariantCulture);
                        if (i == currentPage)
                        {
                            WriteTo(@__razor_helper_writer, pageText);
                        }
                        else
                        {
                            WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(i), pageText));
                        }

                        WriteTo(@__razor_helper_writer, Raw(" "));
                    }
                }

                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (currentPage < lastPage))
                {
                    if (String.IsNullOrEmpty(nextText))
                    {
                        nextText = ">";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(currentPage + 1), nextText));

                    WriteTo(@__razor_helper_writer, Raw(" "));
                }

                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && (currentPage < lastPage - 1))
                {
                    if (String.IsNullOrEmpty(lastText))
                    {
                        lastText = ">>";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText));
                }

                if (renderAjaxContainer && webGrid.IsAjaxEnabled)
                {
                    WriteLiteralTo(@__razor_helper_writer, "        ");

                    WriteLiteralTo(@__razor_helper_writer, "</span>\r\n");
                }
            }));
        }
Beispiel #18
0
        public static IHtmlString GetHtmlWithSelectAllCheckBox(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, WebGridPagerModes mode              = WebGridPagerModes.All,
                                                               string firstText                = null, string previousText   = null, string nextText    = null,
                                                               string lastText                 = null, int numericLinksCount = 5, object htmlAttributes = null,
                                                               string checkBoxValue            = "ID")
        {
            var newColumn = webGrid.Column(header: "{}",
                                           format: item => new HelperResult(writer =>
            {
                writer.Write("<input class=\"singleCheckBox\" name=\"selectedRows\" value=\""
                             + item.Value.GetType().GetProperty(checkBoxValue).GetValue(item.Value, null).ToString()
                             + "\" type=\"checkbox\" />"
                             );
            }));
            var newColumns = columns.ToList();

            newColumns.Insert(0, newColumn);
            var script = @"<script>
                if (typeof jQuery == 'undefined')
                {
                    document.write(
                        unescape(
                        ""%3Cscript src='http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js'%3E%3C/script%3E""
                        )
                     );
                }
                (function(){
                    window.setTimeout(function() { initializeCheckBoxes();  }, 1000);
                    function initializeCheckBoxes(){   
                        $(function () {
                            $('#allCheckBox').live('click',function () {
                                var isChecked = $(this).attr('checked');                       
                                $('.singleCheckBox').attr('checked', isChecked  ? true: false);
                                $('.singleCheckBox').closest('tr').addClass(isChecked  ? 'selected-row': 'not-selected-row');
                                $('.singleCheckBox').closest('tr').removeClass(isChecked  ? 'not-selected-row': 'selected-row');
                            });
                            $('.singleCheckBox').live('click',function () {
                                var isChecked = $(this).attr('checked');
                                $(this).closest('tr').addClass(isChecked  ? 'selected-row': 'not-selected-row');
                                $(this).closest('tr').removeClass(isChecked  ? 'not-selected-row': 'selected-row');
                                if(isChecked && $('.singleCheckBox').length == $('.selected-row').length)
                                     $('#allCheckBox').attr('checked',true);
                                else
                                    $('#allCheckBox').attr('checked',false);
                            });
                        });
                    }
                })();
            </script>";
            var html   = webGrid.GetHtml(tableStyle, headerStyle, footerStyle, rowStyle,
                                         alternatingRowStyle, selectedRowStyle, caption,
                                         displayHeader, fillEmptyRows, emptyRowCellValue,
                                         newColumns, exclusions, mode, firstText,
                                         previousText, nextText, lastText,
                                         numericLinksCount, htmlAttributes
                                         );

            return(MvcHtmlString.Create(html.ToString().Replace("{}",
                                                                "<input type='checkbox' id='allCheckBox'/>") + script));
        }
        /// <param name="mode">Modes for pager rendering.</param>
        /// <param name="firstText">Text for link to first page.</param>
        /// <param name="previousText">Text for link to previous page.</param>
        /// <param name="nextText">Text for link to next page.</param>
        /// <param name="lastText">Text for link to last page.</param>
        /// <param name="numericLinksCount">Number of numeric links that should display.</param>
        /// <param name="explicitlyCalled">The Pager can be explicitly called by the public API or is called by the WebGrid when no footer is provided.
        /// In the explicit scenario, we would need to render a container for the pager to allow identifying the pager links.
        /// In the implicit scenario, the grid table would be the container.
        /// </param>
        private HelperResult Pager(
            WebGridPagerModes mode,
            string firstText,
            string previousText,
            string nextText,
            string lastText,
            int numericLinksCount,
            bool explicitlyCalled)
        {
            if (!_canPage)
            {
                throw new NotSupportedException(HelpersResources.WebGrid_NotSupportedIfPagingIsDisabled);
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (firstText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "FirstLast"), "firstText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (previousText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "NextPrevious"), "previousText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (nextText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "NextPrevious"), "nextText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (lastText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          HelpersResources.WebGrid_PagerModeMustBeEnabled, "FirstLast"), "lastText");
            }
            if (numericLinksCount < 0)
            {
                throw new ArgumentOutOfRangeException("numericLinksCount",
                                                      String.Format(CultureInfo.CurrentCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }

            return WebGridRenderer.Pager(this, HttpContext, mode: mode, firstText: firstText, previousText: previousText, nextText: nextText, lastText: lastText,
                                         numericLinksCount: numericLinksCount, renderAjaxContainer: explicitlyCalled);
        }
        public static HelperResult Pager(
            WebGrid webGrid,
            HttpContextBase httpContext,
            WebGridPagerModes mode,
            string firstText,
            string previousText,
            string nextText,
            string lastText,
            int numericLinksCount,
            bool renderAjaxContainer)
        {
            return new HelperResult(__razor_helper_writer =>
            {
                int currentPage = webGrid.PageIndex;
                int totalPages = webGrid.PageCount;
                int lastPage = totalPages - 1;

                WriteTo(@__razor_helper_writer, GridInitScript(webGrid, httpContext));

                if (renderAjaxContainer && webGrid.IsAjaxEnabled)
                {
                    WriteLiteralTo(@__razor_helper_writer, "        ");

                    WriteLiteralTo(@__razor_helper_writer, "<span data-swhgajax=\"true\" data-swhgcontainer=\"");

                    WriteTo(@__razor_helper_writer, webGrid.AjaxUpdateContainerId);

                    WriteLiteralTo(@__razor_helper_writer, "\" data-swhgcallback=\"");

                    WriteTo(@__razor_helper_writer, webGrid.AjaxUpdateCallback);

                    WriteLiteralTo(@__razor_helper_writer, "\">\r\n");
                }

                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && currentPage > 1)
                {
                    if (String.IsNullOrEmpty(firstText))
                    {
                        firstText = "<<";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(0), firstText));

                    WriteTo(@__razor_helper_writer, Raw(" "));
                }

                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && currentPage > 0)
                {
                    if (String.IsNullOrEmpty(previousText))
                    {
                        previousText = "<";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(currentPage - 1), previousText));

                    WriteTo(@__razor_helper_writer, Raw(" "));
                }

                if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
                {
                    int last = currentPage + (numericLinksCount / 2);
                    int first = last - numericLinksCount + 1;
                    if (last > lastPage)
                    {
                        first -= last - lastPage;
                        last = lastPage;
                    }
                    if (first < 0)
                    {
                        last = Math.Min(last + (0 - first), lastPage);
                        first = 0;
                    }
                    for (int i = first; i <= last; i++)
                    {
                        var pageText = (i + 1).ToString(CultureInfo.InvariantCulture);
                        if (i == currentPage)
                        {
                            WriteTo(@__razor_helper_writer, pageText);
                        }
                        else
                        {
                            WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(i), pageText));
                        }

                        WriteTo(@__razor_helper_writer, Raw(" "));
                    }
                }

                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (currentPage < lastPage))
                {
                    if (String.IsNullOrEmpty(nextText))
                    {
                        nextText = ">";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(currentPage + 1), nextText));

                    WriteTo(@__razor_helper_writer, Raw(" "));
                }

                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && (currentPage < lastPage - 1))
                {
                    if (String.IsNullOrEmpty(lastText))
                    {
                        lastText = ">>";
                    }

                    WriteTo(@__razor_helper_writer, GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText));
                }

                if (renderAjaxContainer && webGrid.IsAjaxEnabled)
                {
                    WriteLiteralTo(@__razor_helper_writer, "        ");

                    WriteLiteralTo(@__razor_helper_writer, "</span>\r\n");
                }
            });
        }
Beispiel #21
0
        public HelperResult GetExtendedHtml(
            string tableStyle          = "table table-striped table-bordered table-hover footable toggle-square",
            string headerStyle         = "webgrid-header",
            string footerStyle         = "webgrid-footer",
            string rowStyle            = null,
            string alternatingRowStyle = null,
            string selectedRowStyle    = null,
            string caption             = null,
            bool displayHeader         = true,
            bool fillEmptyRows         = false,
            string emptyRowCellValue   = null,
            IEnumerable <WebGridColumnHelper> columns = null,
            IEnumerable <string> exclusions           = null,
            WebGridPagerModes mode = WebGridPagerModes.Numeric | WebGridPagerModes.NextPrevious,
            string firstText       = null,
            string previousText    = null,
            string nextText        = null,
            string lastText        = null,
            int numericLinksCount  = 5,
            Object htmlAttributes  = null,
            bool displayTotalItems = true,
            string totalItemsText  = "Total items")
        {
            HtmlString result;

            AdminPages adminPages = new AdminPages();
            AdminPage  adminPage  = adminPages.GetPageByCurrentAction();

            if (adminPages.IsPermissionGranted(adminPage.PageId, PermissionCode.Read))
            {
                WebGrid     webGrid     = this;
                IHtmlString webGridHtml = webGrid.GetHtml(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, columns, exclusions, mode, firstText, previousText, nextText, lastText, numericLinksCount, htmlAttributes);

                string webGridHtmlString = webGridHtml.ToString();

                HtmlDocument htmlDocument = new HtmlDocument();

                //TH Attributes
                htmlDocument.LoadHtml(webGridHtmlString);
                HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectSingleNode("//thead/tr").SelectNodes("th");
                int i = 0;
                foreach (WebGridColumnHelper c in columns)
                {
                    if (c.ThAttributes.IsNotNull())
                    {
                        HtmlNode htmlNodeTh = HtmlNode.CreateNode(htmlNodeCollection[i].OuterHtml.Insert(3, " " + c.ThAttributes + " "));
                        htmlNodeCollection[i].ParentNode.ReplaceChild(htmlNodeTh, htmlNodeCollection[i]);
                    }
                    if (c.DataHide.IsNotNull())
                    {
                        HtmlNode htmlNodeTh = HtmlNode.CreateNode(htmlNodeCollection[i].OuterHtml.Insert(3, " data-hide=\"" + c.DataHide.ToString().ToLower().Split('_').ToCSV(',') + "\" "));
                        htmlNodeCollection[i].ParentNode.ReplaceChild(htmlNodeTh, htmlNodeCollection[i]);
                    }
                    i++;
                }
                webGridHtmlString = htmlDocument.DocumentNode.OuterHtml;

                //Sort icon
                if (webGrid.SortColumn.IsNotEmptyOrWhiteSpace())
                {
                    htmlDocument.LoadHtml(webGridHtmlString);
                    HtmlNode htmlNodeAnchor = htmlDocument.DocumentNode.SelectSingleNode("//a[contains(@href,'sort=" + webGrid.SortColumn + "')]");
                    if (htmlNodeAnchor != null)
                    {
                        string imgSortDirection;
                        if (webGrid.SortDirection == SortDirection.Ascending)
                        {
                            imgSortDirection = "imgSortDirectionASC";
                        }
                        else
                        {
                            imgSortDirection = "imgSortDirectionDESC";
                        }
                        HtmlNode htmlNodeIcon = HtmlNode.CreateNode("<div class=\"" + imgSortDirection + "\"></div>");

                        htmlNodeAnchor.ParentNode.AppendChild(htmlNodeIcon);

                        // Fix a bug http://stackoverflow.com/questions/759355/image-tag-not-closing-with-htmlagilitypack
                        if (HtmlNode.ElementsFlags.ContainsKey("img"))
                        {
                            HtmlNode.ElementsFlags["img"] = HtmlElementFlag.Closed;
                        }
                        else
                        {
                            HtmlNode.ElementsFlags.Add("img", HtmlElementFlag.Closed);
                        }

                        webGridHtmlString = htmlDocument.DocumentNode.OuterHtml;
                    }
                }

                //Total Row Count
                htmlDocument.LoadHtml(webGridHtmlString);
                HtmlNode htmlNodeTFoot = htmlDocument.DocumentNode.SelectSingleNode("//tfoot/tr/td");
                if (htmlNodeTFoot != null)
                {
                    string pager = webGrid.Pager(numericLinksCount: 10, mode: WebGridPagerModes.All).ToString();
                    if (displayTotalItems)
                    {
                        pager = "<span class=\"pager-total-items-text\">" + totalItemsText + ":</span> <span class=\"pager-total-items-value\">" + webGrid.TotalRowCount.ToString() + "</span><span class=\"pager-pagination\">" + pager + "</span>";
                    }

                    htmlNodeTFoot.InnerHtml = pager;

                    // Fix a bug http://stackoverflow.com/questions/759355/image-tag-not-closing-with-htmlagilitypack
                    if (HtmlNode.ElementsFlags.ContainsKey("img"))
                    {
                        HtmlNode.ElementsFlags["img"] = HtmlElementFlag.Closed;
                    }
                    else
                    {
                        HtmlNode.ElementsFlags.Add("img", HtmlElementFlag.Closed);
                    }

                    webGridHtmlString = htmlDocument.DocumentNode.OuterHtml;
                }

                result = new HtmlString(webGridHtmlString);
            }
            else
            {
                result = new HtmlString("<span class=\"label label-danger\">" + Resources.Strings.InsufficientPermissions + "</span>");
            }

            return(new HelperResult(writer =>
            {
                writer.Write(result);
            }));
        }
 public static HelperResult PagerList(this WebGrid webGrid, WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric, string firstText = null, string previousText = null, string nextText = null, string lastText = null, int numericLinksCount = 5, dynamic parameters = null, string actionName = null, int?currentPageIndex = null)
 {
     return(PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, true, parameters, actionName, currentPageIndex ?? webGrid.PageIndex));
 }
Beispiel #23
0
        public HelperResult Pager(
            WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
            string firstText       = null,
            string previousText    = null,
            string nextText        = null,
            string lastText        = null,
            int numericLinksCount  = 5)
        {
            if (!_canPage)
            {
                throw new NotSupportedException("");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (firstText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          "", "FirstLast"), "firstText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (previousText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          "", "NextPrevious"), "previousText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (nextText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          "", "NextPrevious"), "nextText");
            }
            if (!ModeEnabled(mode, WebGridPagerModes.FirstLast) && (lastText != null))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          "", "FirstLast"), "lastText");
            }
            if (numericLinksCount < 0)
            {
                throw new ArgumentOutOfRangeException("numericLinksCount",
                                                      String.Format(CultureInfo.CurrentCulture, "", 0));
            }

            int currentPage = PageIndex;
            int totalPages  = PageCount;
            int lastPage    = totalPages - 1;

            return(new HelperResult(tw =>
            {
                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && currentPage > 1)
                {
                    if (String.IsNullOrEmpty(firstText))
                    {
                        firstText = "<<";
                    }
                    tw.Write(GetPageLinkHtml(0, firstText));
                    tw.Write(" ");
                }
                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && currentPage > 0)
                {
                    if (String.IsNullOrEmpty(previousText))
                    {
                        previousText = "<";
                    }
                    tw.Write(GetPageLinkHtml(currentPage - 1, previousText));
                    tw.Write(" ");
                }

                if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
                {
                    int last = currentPage + (numericLinksCount / 2);
                    int first = last - numericLinksCount + 1;
                    if (last > lastPage)
                    {
                        first -= last - lastPage;
                        last = lastPage;
                    }
                    if (first < 0)
                    {
                        last = Math.Min(last + (0 - first), lastPage);
                        first = 0;
                    }
                    for (int i = first; i <= last; i++)
                    {
                        if (i == currentPage)
                        {
                            tw.Write((i + 1).ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            tw.Write(GetPageLinkHtml(i));
                        }
                        tw.Write(" ");
                    }
                }

                if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && (currentPage < lastPage))
                {
                    if (String.IsNullOrEmpty(nextText))
                    {
                        nextText = ">";
                    }
                    tw.Write(GetPageLinkHtml(currentPage + 1, nextText));
                    tw.Write(" ");
                }
                if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && (currentPage < lastPage - 1))
                {
                    if (String.IsNullOrEmpty(lastText))
                    {
                        lastText = ">>";
                    }
                    tw.Write(GetPageLinkHtml(lastPage, lastText));
                }
            }));
        }
Beispiel #24
0
 private static bool ModeEnabled(WebGridPagerModes mode, WebGridPagerModes modeCheck)
 {
     return (mode & modeCheck) == modeCheck;
 }
    private static HelperResult PagerList(
        WebGrid webGrid,
        WebGridPagerModes mode,
        string firstText,
        string previousText,
        string nextText,
        string lastText,
        int numericLinksCount,
        string paginationStyle,
        bool explicitlyCalled)
    {
        int currentPage = webGrid.PageIndex;
        int totalPages  = webGrid.PageCount;
        int lastPage    = totalPages - 1;

        var ul = new TagBuilder("ul");

        ul.AddCssClass(paginationStyle);

        var li = new List <TagBuilder>();

        if (webGrid.TotalRowCount <= webGrid.PageCount)
        {
            return(new HelperResult(writer =>
            {
                writer.Write(string.Empty);
            }));
        }

        if (ModeEnabled(mode, WebGridPagerModes.FirstLast))
        {
            if (String.IsNullOrEmpty(firstText))
            {
                firstText = "<<";
            }

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(0), firstText)
            };

            if (currentPage == 0)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);
        }

        if (ModeEnabled(mode, WebGridPagerModes.NextPrevious))
        {
            if (String.IsNullOrEmpty(previousText))
            {
                previousText = "<";
            }

            int page = currentPage == 0 ? 0 : currentPage - 1;

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), previousText)
            };

            if (currentPage == 0)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);
        }


        if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
        {
            int last  = currentPage + (numericLinksCount / 2);
            int first = last - numericLinksCount + 1;
            if (last > lastPage)
            {
                first -= last - lastPage;
                last   = lastPage;
            }
            if (first < 0)
            {
                last  = Math.Min(last + (0 - first), lastPage);
                first = 0;
            }
            for (int i = first; i <= last; i++)
            {
                var pageText = (i + 1).ToString(CultureInfo.InvariantCulture);
                var part     = new TagBuilder("li")
                {
                    InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(i), pageText)
                };

                if (i == currentPage)
                {
                    part.MergeAttribute("class", "active");
                }

                li.Add(part);
            }
        }

        if (ModeEnabled(mode, WebGridPagerModes.NextPrevious))
        {
            if (String.IsNullOrEmpty(nextText))
            {
                nextText = ">";
            }

            int page = currentPage == lastPage ? lastPage : currentPage + 1;

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), nextText)
            };

            if (currentPage == lastPage)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);
        }

        if (ModeEnabled(mode, WebGridPagerModes.FirstLast))
        {
            if (String.IsNullOrEmpty(lastText))
            {
                lastText = ">>";
            }

            var part = new TagBuilder("li")
            {
                InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText)
            };

            if (currentPage == lastPage)
            {
                part.MergeAttribute("class", "disabled");
            }

            li.Add(part);
        }

        ul.InnerHtml = string.Join("", li);

        var html = "";

        if (explicitlyCalled && webGrid.IsAjaxEnabled)
        {
            var span = new TagBuilder("span");
            span.MergeAttribute("data-swhgajax", "true");
            span.MergeAttribute("data-swhgcontainer", webGrid.AjaxUpdateContainerId);
            span.MergeAttribute("data-swhgcallback", webGrid.AjaxUpdateCallback);

            span.InnerHtml = ul.ToString();
            html           = span.ToString();
        }
        else
        {
            html = ul.ToString();
        }

        return(new HelperResult(writer =>
        {
            writer.Write(html);
        }));
    }
Beispiel #26
0
        private static HelperResult PagerList(
            WebGrid webGrid,
            WebGridPagerModes mode,
            string firstText,
            string previousText,
            string nextText,
            string lastText,
            int numericLinksCount,
            bool explicitlyCalled)
        {
            int currentPage = webGrid.PageIndex;
            int totalPages = webGrid.PageCount;
            int lastPage = totalPages - 1;

            var ul = new TagBuilder("ul");
            ul.MergeAttribute("class", "pagination pagination-sm sigen-max-height");
            var li = new List<TagBuilder>();

            if (ModeEnabled(mode, WebGridPagerModes.FirstLast))
            {
                if (String.IsNullOrEmpty(firstText))
                {
                    firstText = "<<";
                }

                var part = new TagBuilder("li")
                {
                    InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(0), firstText)
                };

                if (currentPage == 0)
                {
                    part.MergeAttribute("class", "disabled");
                }

                li.Add(part);

            }

            if (ModeEnabled(mode, WebGridPagerModes.NextPrevious))
            {
                if (String.IsNullOrEmpty(previousText))
                {
                    previousText = "<";
                }

                int page = currentPage == 0 ? 0 : currentPage - 1;

                var part = new TagBuilder("li")
                {
                    InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), previousText)
                };

                if (currentPage == 0)
                {
                    part.MergeAttribute("class", "disabled");
                }

                li.Add(part);

            }

            if (ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
            {
                int last = currentPage + (numericLinksCount / 2);
                int first = last - numericLinksCount + 1;
                if (last > lastPage)
                {
                    first -= last - lastPage;
                    last = lastPage;
                }
                if (first < 0)
                {
                    last = Math.Min(last + (0 - first), lastPage);
                    first = 0;
                }
                for (int i = first; i <= last; i++)
                {

                    var pageText = (i + 1).ToString(CultureInfo.InvariantCulture);
                    var part = new TagBuilder("li")
                    {
                        InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(i), pageText)
                    };

                    if (i == currentPage)
                    {
                        part.MergeAttribute("class", "sigen-active");
                    }

                    li.Add(part);

                }
            }

            if (ModeEnabled(mode, WebGridPagerModes.NextPrevious))
            {
                if (String.IsNullOrEmpty(nextText))
                {
                    nextText = ">";
                }

                int page = currentPage == lastPage ? lastPage : currentPage + 1;

                var part = new TagBuilder("li")
                {
                    InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), nextText)
                };

                if (currentPage == lastPage)
                {
                    part.MergeAttribute("class", "disabled");
                }

                li.Add(part);

            }

            if (ModeEnabled(mode, WebGridPagerModes.FirstLast))
            {
                if (String.IsNullOrEmpty(lastText))
                {
                    lastText = ">>";
                }

                var part = new TagBuilder("li")
                {
                    InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText)
                };

                if (currentPage == lastPage)
                {
                    part.MergeAttribute("class", "disabled");
                }

                li.Add(part);

            }

            ul.InnerHtml = string.Join("", li);

            var html = "";
            if (explicitlyCalled && webGrid.IsAjaxEnabled)
            {
                var span = new TagBuilder("span");
                span.MergeAttribute("data-swhgajax", "true");
                span.MergeAttribute("data-swhgcontainer", webGrid.AjaxUpdateContainerId);
                span.MergeAttribute("data-swhgcallback", webGrid.AjaxUpdateCallback);

                span.InnerHtml = ul.ToString();
                html = span.ToString();

            }
            else
            {
                html = ul.ToString();
            }

            /** Registro {} de {} **/
            var numeroRegistros = webGrid.RowsPerPage * webGrid.PageIndex + webGrid.Rows.Count;
            var contenido = string.Concat(
                "<div class='sigen-foot-page'>Registros : ",
                numeroRegistros.ToString(CultureInfo.InvariantCulture),
                " de ",
                webGrid.TotalRowCount.ToString(CultureInfo.InvariantCulture),
                "</div>");
            html = string.Concat(contenido, html);

            return new HelperResult(writer =>
            {
                writer.Write(html);
            });
        }
//------------------------------------------------------------------------------