public static string ConvertDataTableToHtml(TableDataInfo tableDataInfo, string orderBy, string sort) { DataTable dataTable = tableDataInfo.TableData; TableInfoDto tableInfoDto = tableDataInfo.TableInfo; string html = "<table class=\"table table-bordered table-hover table-condensed\"><tbody>"; //add header row html += "<tr>"; for (int i = 0; i < dataTable.Columns.Count; i++) { string colName = dataTable.Columns[i].ColumnName; if (tableInfoDto.ColumnInfos.All(c => c.Name != colName)) { continue; } if (orderBy.ToLower().Equals(colName.ToLower())) { if (sort.ToLower().Equals("asc")) { html += string.Format("<td><a href=\"?tabName={1}&orderby={2}&sort={3}\">{0}</a></td>", TableInfoHelper.GetColumnDesc(tableInfoDto, colName), tableInfoDto.Name, colName, "DESC"); } else { html += string.Format("<td><a href=\"?tabName={1}&orderby={2}&sort={3}\">{0}</a></td>", TableInfoHelper.GetColumnDesc(tableInfoDto, colName), tableInfoDto.Name, colName, "ASC"); } } else { html += string.Format("<td><a href=\"?tabName={1}&orderby={2}&sort={3}\">{0}</a></td>", TableInfoHelper.GetColumnDesc(tableInfoDto, colName), tableInfoDto.Name, colName, "DESC"); } } html += "</tr>"; //add rows for (int i = 0; i < dataTable.Rows.Count; i++) { html += "<tr>"; for (int j = 0; j < dataTable.Columns.Count; j++) { string colName = dataTable.Columns[j].ColumnName; if (tableInfoDto.ColumnInfos.All(c => c.Name != colName)) { continue; } html += "<td>" + dataTable.Rows[i][j].ToString() + "</td>"; } html += "</tr>"; } html += "</tbody></table>"; return(html); }
public static TableModel GetPagerData(ITableInfoService tableInfoService, ITableDataService tableDataService, string tabName, string orderBy, string sort, int pageSize, int pageIndex = 1) { var tabInfo = TableInfoHelper.GetTableInfo(tableInfoService, tabName); pageSize = pageSize <= 0 ? 20 : pageSize; string orderInfo = ""; if (string.IsNullOrEmpty(orderBy) || string.IsNullOrEmpty(sort)) { orderInfo = "[ID] DESC"; } else { orderInfo = string.Format("[{0}] {1}", orderBy, sort); } var tableDataRs = tableDataService.GetPagerData(new GetPagerDataRequest() { TableName = tabInfo.Name, OrderBy = orderInfo, PageSize = pageSize, PageIndex = pageIndex }); tableDataRs.CheckErrorAndThrowIt(); var pagerInfo = tableDataRs.Data; TableDataInfo info = new TableDataInfo { TableData = pagerInfo.PagerData, TableInfo = tabInfo }; Webdiyer.WebControls.Mvc.PagedList <DataRow> arts = new Webdiyer.WebControls.Mvc.PagedList <DataRow>(pagerInfo.PagerData.Select(), pageIndex, pageSize, pagerInfo.RecordCount); TableModel model = new TableModel(); var requestInfo = new Models.RequestInfo { OrderBy = orderBy, Sort = sort, PageIndex = pageIndex }; model.PagedList = arts; model.TableInfo = info; model.RequestInfo = requestInfo; return(model); }