Beispiel #1
0
 protected GridColumn(GridColumnContext <TRow> context)
 {
     Context = context;
 }
Beispiel #2
0
        public virtual bool CreateCell(StringBuilder cells, object cellData, string columnClassPrefix, bool isHeader, bool isTotal, GridColumnContext <TRow> context, object htmlAttributes)
        {
            var cell = new HtmlTagBuilder("div");

            int width = AddColClass(cell, columnClassPrefix, "xs", Position.Width(0), -1);

            width = AddColClass(cell, columnClassPrefix, "sm", Position.Width(1), width);
            width = AddColClass(cell, columnClassPrefix, "md", Position.Width(2), width);
            width = AddColClass(cell, columnClassPrefix, "lg", Position.Width(3), width);

            int offset = AddOffsetClass(cell, columnClassPrefix, "xs", Position.Offset(0), 0);

            offset = AddOffsetClass(cell, columnClassPrefix, "sm", Position.Offset(1), offset);
            offset = AddOffsetClass(cell, columnClassPrefix, "md", Position.Offset(2), offset);
            offset = AddOffsetClass(cell, columnClassPrefix, "lg", Position.Offset(3), offset);

            string style = Context.Style.ToString().ToLowerInvariant();

            if (Context.Style != GridColumnStyle.Text)
            {
                cell.AddCssClass(columnClassPrefix + "-" + style);
            }
            if (isHeader)
            {
                if (context.WrapHeader)
                {
                    cell.AddCssClass("wrap");
                }
                string valueId  = context.Index.ToString(CultureInfo.InvariantCulture);
                var    sortable = context.IsSortable;
                if (sortable != GridBooleanPlus.False)
                {
                    cell.MergeAttribute("data-sortable", valueId);
                    if (sortable != GridBooleanPlus.True)
                    {
                        cell.MergeAttribute("data-sortable-type", sortable.ToString().ToLowerInvariant());
                    }
                }
                var filterable = context.IsFilterable;
                if (filterable != GridBooleanPlus.False)
                {
                    cell.MergeAttribute("data-filterable", valueId);
                    if (filterable != GridBooleanPlus.True)
                    {
                        cell.MergeAttribute("data-filterable-type", filterable.ToString().ToLowerInvariant());
                    }
                }
                var groupable = context.IsGroupable;
                if (groupable != GridBooleanPlus.False)
                {
                    cell.MergeAttribute("data-groupable", valueId);
                    if (groupable != GridBooleanPlus.True)
                    {
                        cell.MergeAttribute("data-groupable-type", groupable.ToString().ToLowerInvariant());
                    }
                    var groupsExpanded = context.GroupsExpanded;
                    if (groupsExpanded != GridGroupsExpanded.First)
                    {
                        cell.MergeAttribute("data-groupable-expanded", groupsExpanded.ToString().ToLowerInvariant());
                    }
                }
            }
            else if (isTotal && context.Total > GridColumnTotal.Title) // Skip total titles
            {
                cell.MergeAttribute("data-total", context.Index.ToString(CultureInfo.InvariantCulture));
                cell.MergeAttribute("data-total-type", context.Total.ToString().ToLowerInvariant());
                switch (context.Subtotal)
                {
                case GridColumnSubtotal.Prefix:
                    if (context.Prefix != null)
                    {
                        cell.MergeAttribute("data-total-sub", "true");
                    }
                    break;

                case GridColumnSubtotal.Suffix:
                    if (context.Suffix != null)
                    {
                        cell.MergeAttribute("data-total-sub", "true");
                    }
                    break;
                }
                cell.MergeAttribute("data-total-style", context.Style.ToString().ToLowerInvariant());
            }
            bool hasData;

            if (cellData == null)
            {
                hasData = false;
            }
            else
            {
                string cellString = cellData.ToString();
                if (string.IsNullOrWhiteSpace(cellString))
                {
                    hasData = false;
                }
                else
                {
                    cell.InnerHtml = cellString;
                    hasData        = true;
                }
            }

            cell.MergeAttributes(htmlAttributes);
            AddCell(cells, cell);

            AddClearFix(cells, "visible-xs", Position.EndOfRow(0));
            AddClearFix(cells, "visible-sm", Position.EndOfRow(1));
            AddClearFix(cells, "visible-md", Position.EndOfRow(2));
            AddClearFix(cells, "visible-lg", Position.EndOfRow(3));

            return(hasData);
        }