static ModelTableController() { MenuOrder = 55; ListFields.RemoveField("Controller", "TableName", "ConnName"); { var df = ListFields.AddListField("Columns", "Enable"); df.Header = "列集合"; df.DisplayName = "列集合"; df.Url = "ModelColumn?tableId={Id}"; } ModelTableSetting = table => { var columns = table.GetColumns(); // 不在列表页显示 var fields = columns.FindAll(fa => fa.ShowInList && (fa.Name.EqualIgnoreCase(ModelTable._.Controller) || fa.Name.EqualIgnoreCase(ModelTable._.TableName) || fa.Name.EqualIgnoreCase(ModelTable._.ConnName))); foreach (var field in fields) { field.ShowInList = false; } // 调整列宽 columns.Find(f => f.Name.EqualIgnoreCase(ModelTable._.Name)).Width = "115"; columns.Find(f => f.Name.EqualIgnoreCase(ModelTable._.DisplayName)).Width = "115"; columns.Find(f => f.Name.EqualIgnoreCase(ModelTable._.Url)).Width = "200"; columns.Save(); // 添加列 var column = ModelColumn.FindByTableIdAndName(table.Id, "Columns") ?? new ModelColumn { TableId = table.Id, Name = "Columns", DisplayName = "列集合", //CellText = "列集合", //CellTitle = "列集合", CellUrl = "/Admin/ModelColumn?tableId={id}", ShowInList = true, Enable = true, Sort = 5, Width = "80", }; column.Save(); return(table); }; }
/// <summary> /// Generates a ModelColumn list /// </summary> /// <param name="data"></param> /// <returns></returns> public List <ModelColumn> GenerateModels(DataSourceItemModel[] data) { var columns = new List <ModelColumn>(); foreach (var model in data) { var column = new ModelColumn { DataType = model.DataType, Name = model.DataSource + "_" + model.Column, Label = string.IsNullOrWhiteSpace(model.Label) ? model.Column.Humanize() : model.Label, Visible = true, Sortable = true, MetaAggregate = model.Aggregation, HasFilter = true }; column.Template = CodeGenerator.GetTemplateByDataType(column.Name, column.DataType); column.EditorType = CodeGenerator.GetEditorTypeByDataType(column.DataType); column.Searchable = column.DataType == DataType.String; if (string.IsNullOrWhiteSpace(model.Filter) == false) { column.Filter = new Filter(); if (model.Filter.StartsWith("=")) { column.Filter.Text = model.Filter.Substring(1).Trim(); column.Filter.Operator = CompareOperators.Contains; } else if (model.Filter.StartsWith("!=")) { column.Filter.Text = model.Filter.Substring(2).Trim(); column.Filter.Operator = CompareOperators.NotContains; } else if (model.Filter.StartsWith(">=")) { column.Filter.Text = model.Filter.Substring(2).Trim(); column.Filter.Operator = CompareOperators.Gte; } else if (model.Filter.StartsWith("<=")) { column.Filter.Text = model.Filter.Substring(2).Trim(); column.Filter.Operator = CompareOperators.Lte; } else if (model.Filter.StartsWith(">")) { column.Filter.Text = model.Filter.Substring(1).Trim(); column.Filter.Operator = CompareOperators.Gt; } else if (model.Filter.StartsWith("<")) { column.Filter.Text = model.Filter.Substring(1).Trim(); column.Filter.Operator = CompareOperators.Gt; } } columns.Add(column); } return(columns); }