private void RenderBody(Models.RenderingModel model, StringBuilder sbHtml, GridContext gridContext)
        {
            sbHtml.AppendLine("<tbody>");

            foreach (var row in model.Rows)
            {
                sbHtml.Append("<tr");
                AppendCssAttribute(row.CalculatedCssClass, sbHtml);
                sbHtml.AppendLine(">");

                if (model.ShowCheckBox)
                {
                    var cell = row.Cells[model.KeyId];
                    sbHtml.Append("<td");
                    AppendCssAttribute(cell.CalculatedCssClass, sbHtml);
                    sbHtml.Append(">");
                    sbHtml.AppendFormat("<input type='checkbox' class='checkboxes' value='{0}' data-id='{0}'>", cell.HtmlText);
                    sbHtml.Append("</td>");
                }
                foreach (var col in model.Columns)
                {
                    var cell = row.Cells[col.Name];

                    sbHtml.Append("<td");
                    AppendCssAttribute(cell.CalculatedCssClass, sbHtml);
                    sbHtml.Append(">");
                    sbHtml.Append(cell.HtmlText);
                    sbHtml.Append("</td>");
                }
                sbHtml.AppendLine("  </tr>");
            }

            sbHtml.AppendLine("</tbody>");
        }
Beispiel #2
0
        private void RenderBody(Models.RenderingModel model, StringBuilder sbHtml)
        {
            sbHtml.AppendLine("<tbody>");

            foreach (var row in model.Rows)
            {
                sbHtml.Append("<tr");
                AppendCssAttribute(row.CalculatedCssClass, sbHtml);
                sbHtml.AppendLine(">");

                foreach (var col in model.Columns)
                {
                    var cell = row.Cells[col.Name];

                    sbHtml.Append("<td");
                    AppendCssAttribute(cell.CalculatedCssClass, sbHtml);
                    sbHtml.Append(">");
                    sbHtml.Append(cell.HtmlText);
                    sbHtml.Append("</td>");
                }
                sbHtml.AppendLine("  </tr>");
            }

            sbHtml.AppendLine("</tbody>");
        }
        private void RenderHeader(Models.RenderingModel model, StringBuilder sbHtml, GridContext gridContext)
        {
            sbHtml.AppendLine("<thead>");
            sbHtml.AppendLine("  <tr>");
            if (model.ShowCheckBox)
            {
                sbHtml.Append("<th");
                sbHtml.Append(">");
                // sbHtml.AppendLine("<input type=\"checkbox\" class=\"group-checkable\" data-mvcgrid-type=\"allcheckselect\" data-mvcgrid-name=\"" + gridContext.GridName + "\"/>");
                sbHtml.AppendLine("</th>");
            }
            foreach (var col in model.Columns)
            {
                sbHtml.Append("<th");

                if (!String.IsNullOrWhiteSpace(col.Onclick))
                {
                    sbHtml.Append(" style='cursor: pointer;'");
                    sbHtml.AppendFormat(" onclick='{0}'", col.Onclick);
                }
                sbHtml.Append(">");

                sbHtml.Append(col.HeaderText);

                if (col.SortIconDirection.HasValue)
                {
                    switch (col.SortIconDirection)
                    {
                    case Models.SortDirection.Asc:
                        sbHtml.Append(" ");
                        sbHtml.Append(HtmlImageSortAsc);
                        break;

                    case Models.SortDirection.Dsc:
                        sbHtml.Append(" ");
                        sbHtml.Append(HtmlImageSortDsc);
                        break;

                    case Models.SortDirection.Unspecified:
                        sbHtml.Append(" ");
                        sbHtml.Append(HtmlImageSort);
                        break;
                    }
                }
                sbHtml.AppendLine("</th>");
            }
            sbHtml.AppendLine("  </tr>");
            sbHtml.AppendLine("</thead>");
        }
Beispiel #4
0
        public void Render(Models.RenderingModel model, Models.GridContext gridContext, TextWriter outputStream)
        {
            var sw = outputStream;

            StringBuilder sbHeaderRow = new StringBuilder();

            foreach (var col in model.Columns)
            {
                if (col.VisibilityExport)
                {
                    if (sbHeaderRow.Length != 0)
                    {
                        sbHeaderRow.Append(",");
                    }
                    sbHeaderRow.Append(CsvEncode(col.HeaderText));
                }
            }
            sbHeaderRow.AppendLine();
            sw.Write(sbHeaderRow.ToString());

            foreach (var item in model.Rows)
            {
                StringBuilder sbRow = new StringBuilder();
                foreach (var col in model.Columns)
                {
                    if (col.VisibilityExport)
                    {
                        var cell = item.Cells[col.Name];

                        if (sbRow.Length != 0)
                        {
                            sbRow.Append(",");
                        }

                        string val = cell.PlainText;

                        sbRow.Append(CsvEncode(val));
                    }
                }
                sbRow.AppendLine();
                sw.Write(sbRow.ToString());
            }
        }
Beispiel #5
0
        private void RenderHeader(Models.RenderingModel model, StringBuilder sbHtml)
        {
            sbHtml.AppendLine("<thead>");
            sbHtml.AppendLine("  <tr>");
            foreach (var col in model.Columns)
            {
                sbHtml.Append("<th");

                if (!String.IsNullOrWhiteSpace(col.Onclick))
                {
                    sbHtml.Append(" style='cursor: pointer;'");
                    sbHtml.AppendFormat(" onclick='{0}'", col.Onclick);
                }
                sbHtml.Append(">");

                sbHtml.Append(col.HeaderText);

                if (col.SortIconDirection.HasValue)
                {
                    switch (col.SortIconDirection)
                    {
                    case Models.SortDirection.Asc:
                        sbHtml.Append(" ");
                        sbHtml.Append(HtmlImageSortAsc);
                        break;

                    case Models.SortDirection.Dsc:
                        sbHtml.Append(" ");
                        sbHtml.Append(HtmlImageSortDsc);
                        break;

                    case Models.SortDirection.Unspecified:
                        sbHtml.Append(" ");
                        sbHtml.Append(HtmlImageSort);
                        break;
                    }
                }
                sbHtml.AppendLine("</th>");
            }
            sbHtml.AppendLine("  </tr>");
            sbHtml.AppendLine("</thead>");
        }
Beispiel #6
0
        private void RenderPaging(Models.RenderingModel model, StringBuilder sbHtml)
        {
            if (model.PagingModel == null)
            {
                return;
            }

            Models.PagingModel pagingModel = model.PagingModel;

            sbHtml.Append("<div class=\"row\">");
            sbHtml.Append("<div class=\"col-xs-6\">");
            sbHtml.AppendFormat(model.SummaryMessage,
                                pagingModel.FirstRecord, pagingModel.LastRecord, pagingModel.TotalRecords
                                );
            sbHtml.Append("</div>");


            sbHtml.Append("<div class=\"col-xs-6\">");
            int pageToStart;
            int pageToEnd;

            pagingModel.CalculatePageStartAndEnd(5, out pageToStart, out pageToEnd);

            sbHtml.Append("<ul class='pagination pull-right' style='margin-top: 0;'>");

            sbHtml.Append("<li");
            if (pageToStart == pagingModel.CurrentPage)
            {
                sbHtml.Append(" class='disabled'");
            }
            sbHtml.Append(">");

            sbHtml.AppendFormat("<a href='#' aria-label='{0}' ", model.PreviousButtonCaption);
            if (pageToStart < pagingModel.CurrentPage && pagingModel.PageLinks.Count > (pagingModel.CurrentPage - 1))
            {
                sbHtml.AppendFormat("onclick='{0}'", pagingModel.PageLinks[pagingModel.CurrentPage - 1]);
            }
            else
            {
                sbHtml.AppendFormat("onclick='{0}'", "return false;");
            }
            sbHtml.Append(">");
            sbHtml.AppendFormat("<span aria-hidden='true'>&laquo; {0}</span></a></li>", model.PreviousButtonCaption);

            for (int i = pageToStart; i <= pageToEnd; i++)
            {
                sbHtml.Append("<li");
                if (i == pagingModel.CurrentPage)
                {
                    sbHtml.Append(" class='active'");
                }
                sbHtml.Append(">");
                sbHtml.AppendFormat("<a href='#' onclick='{0}'>{1}</a></li>", pagingModel.PageLinks[i], i);
            }


            sbHtml.Append("<li");
            if (pageToEnd == pagingModel.CurrentPage)
            {
                sbHtml.Append(" class='disabled'");
            }
            sbHtml.Append(">");

            sbHtml.AppendFormat("<a href='#' aria-label='{0}' ", model.NextButtonCaption);
            if (pageToEnd > pagingModel.CurrentPage)
            {
                sbHtml.AppendFormat("onclick='{0}'", pagingModel.PageLinks[pagingModel.CurrentPage + 1]);
            }
            else
            {
                sbHtml.AppendFormat("onclick='{0}'", "return false;");
            }
            sbHtml.Append(">");
            sbHtml.AppendFormat("<span aria-hidden='true'>{0} &raquo;</span></a></li>", model.NextButtonCaption);

            sbHtml.Append("</ul>");
            sbHtml.Append("</div>");
            sbHtml.Append("</div>");
        }
Beispiel #7
0
        public void Render(Models.RenderingModel model, Models.GridContext gridContext, System.IO.TextWriter outputStream)
        {
            //model.
            string template = @"
@using MVCGrid.Models
@helper SortImage(Column col){
    
    if (col.SortIconDirection.HasValue)
    {
        switch (col.SortIconDirection)
        {
            case SortDirection.Asc:
                <img src='@(Model.HandlerPath)/sortup.png' class='pull-right' />
                break;
            case SortDirection.Dsc:
                <img src='@(Model.HandlerPath)/sortdown.png' class='pull-right' />
                break;
            case SortDirection.Unspecified:
                <img src='@(Model.HandlerPath)/sort.png' class='pull-right' />
                break;
        }
    }
}

@helper PageLink(int pageNum, string link, int currentPage){

    if (pageNum == currentPage){
        <li class='active'><a href='#' onclick='@Raw(link)'>@pageNum</a></li>
    }
    else{
        <li><a href='#' onclick='@Raw(link)'>@pageNum</a></li>
    }
}
@helper PageNextLink(int pageToEnd, PagingModel pagingModel){
    string attr="""";
    if (pageToEnd == pagingModel.CurrentPage){
        attr="" class='disabled'"";
    }
    string onclick = """";
    if (pageToEnd > pagingModel.CurrentPage){
        onclick = pagingModel.PageLinks[pagingModel.CurrentPage + 1] + ""; "";
    }

    <li@(Raw(attr))>
        <a href='#' aria-label='Next' onclick='@(Raw(onclick))return false;'><span aria-hidden='true'>Next &raquo;</span></a>
    </li>
}
@helper PagePreviousLink (int pageToStart, PagingModel pagingModel){
    string attr="""";
    if (pageToStart == pagingModel.CurrentPage){
        attr="" class='disabled'"";
    }
    string onclick = """";
    if (pageToStart < pagingModel.CurrentPage){
        onclick = pagingModel.PageLinks[pagingModel.CurrentPage - 1] + ""; "";
    }

    <li@(Raw(attr))>
        <a href='#' aria-label='Previous' onclick='@(Raw(onclick))return false;'><span aria-hidden='true'>&laquo; Previous</span></a>
    </li>
}

@functions {
    // Pass a user name to this method.
    string HeaderAttributes(Column col)
    {
        string str="""";
        if (col.Onclick != null){
            str="" style='cursor: pointer;'"";
            str += String.Format("" onclick='{0}'"", col.Onclick);
        }
        return str;
    }

    string AppendCssAttribute(string classString)
    {
        if (!String.IsNullOrWhiteSpace(classString))
        {
            return String.Format("" class='{0}'"", classString);
        }
        return """";
    }
    
}

<table id=""@Model.TableHtmlId"" class=""table table-striped table-bordered"">
    <thead>
        <tr>
            @foreach (var col in Model.Columns){
                <th@(Raw(HeaderAttributes(col)))>@col.HeaderText @(SortImage(col))</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var row in Model.Rows)
        {
            <tr@(Raw(AppendCssAttribute(row.CalculatedCssClass)))>
                @foreach (var col in Model.Columns)
                {
                    var cell = row.Cells[col.Name];
                    <td@(Raw(AppendCssAttribute(cell.CalculatedCssClass)))>@Raw(cell.HtmlText)</td>
                }
            </tr>
        }
    </tbody>
</table>

@if (Model.PagingModel != null){
    var pagingModel = Model.PagingModel;
    int pageToStart;
    int pageToEnd;
    pagingModel.CalculatePageStartAndEnd(5, out pageToStart, out pageToEnd);

    <div class='row'>
        <div class='col-xs-6'>
            Showing @pagingModel.FirstRecord to @pagingModel.LastRecord of @pagingModel.TotalRecords entries
        </div>
        <div class='col-xs-6'>
            <ul class='pagination pull-right' style='margin-top: 0;'>
                @PagePreviousLink(pageToStart, pagingModel)
                @for (int i = pageToStart; i <= pageToEnd; i++)
                {
                    <text>@PageLink(i, pagingModel.PageLinks[i], pagingModel.CurrentPage)</text>
                }
                @PageNextLink(pageToEnd, pagingModel)
            </ul>
        </div>
    </div>
}
";//

            string templateKey = "Output";

            var result = RazorEngine.Engine.Razor.RunCompile(template, templateKey, typeof(Models.RenderingModel), model);


            outputStream.Write(result);
        }