Esempio n. 1
0
        public IGridWithOptions <T> Columns(Action <ColumnBuilder <T> > columnBuilder)
        {
            var builder = new ColumnBuilder <T>();

            var html = new HtmlHelper(_context, new ViewPage());

            //显示Checkbox
            if (Model.ShowCheckBox)
            {
                builder.For(f => html.SiCheckBox(typeof(T).Name, ""), "Id")
                .Header(x => html.SiCheckBox(typeof(T).Name, ""))
                .Sortable(false)
                .Align(Alignment.Center)
                .Width(30)
                .Queryable(false);
            }


            //显示行号
            if (Model.ShowRowNumber)
            {
                builder.For(x => "").IsRowNumberColumn(true).Align(Alignment.Center).Width(40).Queryable(false);
            }

            columnBuilder(builder);

            foreach (var column in builder)
            {
                //列初始化
                InitColumns(column);

                if (column.Position == null)
                {
                    _gridModel.Columns.Add(column);
                }
                else
                {
                    _gridModel.Columns.Insert(column.Position.Value, column);
                }

                if (DataSource != null && column.IsSumColumn)
                {
                    if (DataSource.DicSum == null)
                    {
                        DataSource.DicSum = new Dictionary <string, decimal>();
                    }

                    DataSource.DicSum.Add(new KeyValuePair <string, decimal>(column.FieldName, 0M));
                }
            }

            return(this);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new instance of the GridModel class
 /// </summary>
 public GridModel()
 {
     _emptyText     = "没有任何数据.";
     _columnBuilder = CreateColumnBuilder();
 }