Esempio n. 1
0
        internal TagBuilder BuildDataTableBody(DataTableContext dataTableContext)
        {
            var tbody = new TagBuilder("tbody");

            tbody.AddCssClass("kt-datatable__body");

            if (Fields.IsNotNull() && Fields.Any())
            {
                var list = ((IEnumerable <Object>)Dataset).ToList();

                for (var j = 0; j < list.Count; j++)
                {
                    var item = list[j];

                    var row = BuildRow(j % 2 == 1 ? "kt-datatable__row--even" : "");

                    var type = item.GetType();

                    for (var i = 0; i < Fields.Count; i++)
                    {
                        var field = Fields[i];

                        var value = type.GetProperty(field.Name).GetValue(item, null).ToString();

                        AppendDataTableCell(row, dataTableContext, field, "td", value, i);
                    }

                    AppendTemplateCellToEnding(row, dataTableContext, "td");

                    tbody.InnerHtml.AppendHtml(row);
                }
            }

            return(tbody);
        }
Esempio n. 2
0
        internal TagBuilder BuildDataTableHead(DataTableContext dataTableContext)
        {
            if (Fields.IsNull())
            {
                Fields = Dataset.GetType().GetProperty("Item").PropertyType.GetProperties().Select(t => new DataField {
                    Name = t.Name
                }).ToList();
            }

            var thead = new TagBuilder("thead");

            thead.AddCssClass("kt-datatable__head");

            var row = BuildRow();

            for (var i = 0; i < Fields.Count; i++)
            {
                var field = Fields[i];

                AppendDataTableCell(row, dataTableContext, field, "th", "", i);
            }

            AppendTemplateCellToEnding(row, dataTableContext, "th");

            thead.InnerHtml.AppendHtml(row);

            return(thead);
        }
Esempio n. 3
0
        internal void AppendDataTableCell(TagBuilder row, DataTableContext dataTableContext, DataField field, string tagName, string value, int columnIndex)
        {
            var checkboxColumn = dataTableContext.CheckboxColumns.FirstOrDefault(t => t.FieldName == field.Name);

            var templateColumn = dataTableContext.TemplateColumns.FirstOrDefault(t => t.Item1.FieldName == field.Name);

            var cell = BuildCell(tagName, field);

            if (checkboxColumn.IsNotNull())
            {
                BuildDataTableCheckboxCell(cell, value);
            }
            else if (templateColumn.IsNotNull())
            {
                BuildDataTableTemplateCell(cell, templateColumn);
            }
            else
            {
                AppendTemplateCellByIndex(row, dataTableContext, field, tagName, columnIndex);

                BuildDataTableTextCell(cell, field, value);
            }

            row.InnerHtml.AppendHtml(cell);
        }
Esempio n. 4
0
        internal void AppendTemplateCellByIndex(TagBuilder row, DataTableContext dataTableContext, DataField field, string tagName, int columnIndex)
        {
            var templateColumn2 = dataTableContext.TemplateColumns.FirstOrDefault(t => t.Item1.Index == columnIndex && String.IsNullOrWhiteSpace(t.Item1.FieldName));

            if (templateColumn2.IsNotNull())
            {
                var cell = BuildCell(tagName, field);

                BuildDataTableTemplateCell(cell, templateColumn2);

                row.InnerHtml.AppendHtml(cell);
            }
        }
Esempio n. 5
0
        internal void AppendTemplateCellToEnding(TagBuilder row, DataTableContext dataTableContext, string tagName)
        {
            var templateColumns2 = dataTableContext.TemplateColumns.Where(t => t.Item1.Index < 0 && String.IsNullOrWhiteSpace(t.Item1.FieldName));

            if (templateColumns2.Any())
            {
                foreach (var templateColumn in templateColumns2)
                {
                    var cell = BuildCell(tagName, null);

                    BuildDataTableTemplateCell(cell, templateColumn);

                    row.InnerHtml.AppendHtml(cell);
                }
            }
        }