public virtual HtmlField AddField <T>(string ColumnTitle, string DataBind, int Width, bool Sortable = false, string ColumnNameBD = "", bool EnableCheckAll = false) where T : HtmlField { var c = (HtmlField)Activator.CreateInstance(typeof(T), this); c.ColumnTitle = ColumnTitle; c.DataBind = DataBind; c.Width = Width; c.Sortable = Sortable; c.EnableCheckAll = EnableCheckAll; c.ColumnNameBD = ColumnNameBD; HtmlFields.Add(c); return(c); }
public override string ToString() { var table = new StringBuilder(); var loadingClass = (Loading == null || Loading.Class == null) ? "col-md-3 col-md-offset-4" : Loading.Class; var loadingDatabindProperty = (Loading == null || Loading.DatabindProperty == null) ? "ListLoaded()" : Loading.DatabindProperty; #region Loading Dialog table.AppendLine("<div id='loading' class='" + loadingClass + "' style='margin-top: 25px;' data-bind='visible: !listLoaded()'>"); table.AppendLine(" <div class='widget-body'>"); table.AppendLine(" <img src='" + HelperConstants.Cdn + "/images/loading.gif' style='width: 50px; height: 50px;'>"); table.AppendLine(" <span style='margin-left: 12px; color: #737373;'>Carregando...</span>"); table.AppendLine(" </div>"); table.AppendLine("</div>"); #endregion Loading Dialog table.AppendLine("<div class='widget' data-bind='visible: listLoaded()' style='display: none;'>"); var enablePagging = (Pagging != null); var reloadTableDatabind = ReloadTableDatabind ?? "click: _loadTable"; #region Add Button / Search table.AppendLine(" <div class='widget-header with-footer'>"); if (AddButton != null) { table.AppendLine(AddButton.GetHtmlString()); } else if (EnableAddButton) { table.AppendLine(" <span class='widget-caption' style='margin-top: 7px'><a class='btn btn-primary btn-xs' href='#' id='btnAdd' data-bind='click: modalCreate'><i class='fa fa-plus'></i> Adicionar</a></span>"); } if (EnableSearch) { table.AppendLine(" <div class='widget-buttons col-xs-2 pull-right' style='margin-top: 5px'>"); table.AppendLine(" <div class='input-group input-group-xs'>"); if (this.HtmlAdvancedSearch != null) { table.AppendLine(this.HtmlAdvancedSearch.ToString()); } else { table.AppendLine(" <input type='text' class='form-control' placeholder='Pesquisar' data-bind='value: searchValue, event:{keypress: resetSearchKeyPress}'>"); table.AppendLine(" <span class='input-group-btn'>"); table.AppendLine(" <button class='btn btn-default' style='margin-top: 0.25px;' type='button' data-bind='click: resetSearch'>OK</button>"); table.AppendLine(" </span>"); } table.AppendLine(" </div>"); table.AppendLine(" </div>"); } if (enablePagging) { table.AppendLine(" <div class='widget-buttons col-xs-2 pull-right' style='margin-top: 5px'>"); table.AppendLine(" <div class='input-group input-group-xs' style='float: right;'>"); table.AppendLine(" <select id='recordsPerPage' data-bind='event: { change: updateRecordsPerPage }' class='form-control' style='border-top-right-radius: 0; border-bottom-right-radius: 0; border-top-left-radius: 0; border-bottom-left-radius: 0;'>"); Pagging.RecordsPerPage.ForEach(c => table.AppendLine(string.Format("<option value='{0}'>{0} linhas por página</option>", c))); table.AppendLine(" </select>"); table.AppendLine(" </div>"); table.AppendLine(" </div>"); } table.AppendLine(" </div>"); #endregion Add Button / Search table.AppendLine(" <div class='widget-body'>"); if (this.Responsive) { table.AppendLine(" <div class=\"table-responsive\">"); } table.AppendFormat(" <table id='{0}' class='table dataTable table-striped table-bordered table-hover {1}'>", this.Id, this.HtmlAdvancedSearch != null ? "advanced-search" : string.Empty); #region Header table.AppendLine(" <thead>"); table.AppendLine(" <tr>"); HtmlFields.ForEach(c => table.AppendLine(c.HtmlHeader)); table.AppendLine(" </tr>"); table.AppendLine(" </thead>"); #endregion Header #region Body var tableDatabind = string.IsNullOrEmpty(this.DataBind) ? "table" : this.DataBind; table.AppendLine(" <tbody data-bind='foreach: " + tableDatabind + "'>"); table.AppendLine(" <tr>"); HtmlFields.ForEach(c => table.AppendLine(c.HtmlRow)); table.AppendLine(" </tr>"); table.AppendLine(" </tbody>"); #endregion Body #region Footer table.AppendLine(" <tfoot>"); table.AppendLine(" <tr data-bind='visible: table().length == 0'>"); table.AppendLine(" <td colspan='" + this.HtmlFields.Count + "' style='text-align: center'>"); table.AppendLine(" Nenhum registro encontrado"); table.AppendLine(" <br/> <input type='button' class='btn btn-primary btn-xs' data-bind='click: _loadTable' style='margin-top: 15px;' value='Reinicie sua busca'>"); table.AppendLine(" </td>"); table.AppendLine(" </tr>"); //if (enablePagging) //{ // table.AppendLine(" <tr data-bind='visible: " + this.DataBind + "().length > 0'>"); // table.AppendLine(" <td colspan='3'>"); // table.AppendLine(" <small class='pull-left'>Página: <span data-bind='text: PageNumber'></span> <div data-bind='visible: TotalPages() > 0' style='float: right; margin-left: 3px;'> de <span data-bind='text: TotalPages'></span></div></small>"); // table.AppendLine(" </td>"); // table.AppendLine(" <td colspan='5'>"); // table.AppendLine(" <small class='pull-right'>Ir para a página: <input type='text' id='goToPageNumber' style='width: 50px; padding-left: 5px' maxlength='4' value='1' data-bind='value: NextPage' >"); // table.AppendLine(" <input type='button' id='goToPageButton' class='btn btn-primary btn-xs' data-bind='" + Pagging.GoToPageDatabind + "' value='ok' />"); // table.AppendLine(" </small>"); // table.AppendLine(" </td>"); // table.AppendLine(" </tr>"); //} table.AppendLine(" </tfoot>"); #endregion Footer table.AppendLine(" </table>"); if (this.Responsive) { table.AppendLine(" </div>"); } if (enablePagging) { table.AppendLine(" <div class='row'>"); table.AppendLine(" <div class='col-sm-5'>"); table.AppendLine(" <div class='dataTables_info' id='data_info' role='status' aria-live='polite'>"); table.AppendLine(" Página <input id='goToPageNumber' style='width: 22px;' value='1' type='text' data-bind='event: { 'keyup': goToPage }, value: pageNumber'> "); table.AppendLine(" de <span data-bind='text: totalPages'><span>"); table.AppendLine(" </div>"); table.AppendLine(" </div>"); table.AppendLine(" <div class='col-sm-7'>"); table.AppendLine(" <div class='dataTables_paginate paging_simple_numbers pull-right' style='display:inline-block;' id='data_paginate'>"); table.AppendLine(" <ul class='pagination'>"); table.AppendLine(" <li class='paginate_button previous' id='data_previous' data-bind='click: goToFirstPage'>"); table.AppendLine(" <a href='javascript:void(0)' title='Primeira página'><i class='fa fa-fast-backward'></i></a>"); table.AppendLine(" </li>"); table.AppendLine(" <li class='paginate_button previous' id='data_previous' data-bind='click: previousPage'>"); table.AppendLine(" <a href='javascript:void(0)' title='Página anterior'><i class='fa fa-step-backward'></i></a>"); table.AppendLine(" </li>"); table.AppendLine(" <li class='paginate_button next' id='data_next' data-bind='click: nextPage'>"); table.AppendLine(" <a href='javascript:void(0)' title='Próxima página'><i class='fa fa-step-forward'></i></a>"); table.AppendLine(" </li>"); table.AppendLine(" <li class='paginate_button next' id='data_next' data-bind='click: goToLastPage'>"); table.AppendLine(" <a href='javascript:void(0)' title='Última página'><i class='fa fa-fast-forward'></i></a>"); table.AppendLine(" </li>"); table.AppendLine(" </ul>"); table.AppendLine(" </div>"); table.AppendLine(" </div>"); table.AppendLine(" </div>"); } table.AppendLine(" </div>"); table.AppendLine("</div>"); return(table.ToString()); }