Ejemplo n.º 1
0
        private string CreateEmployeeUrl(PageSizes sizes, ResourceUriType type)
        {
            switch (type)
            {
            case ResourceUriType.PreviousPage:
                return(Url.Link("Employees",
                                new
                {
                    fields = sizes.Fields,
                    pageNumber = sizes.PageNumber - 1,
                    pageSize = sizes.PageSize
                }));

            case ResourceUriType.Nextpage:
                return(Url.Link("Employees",
                                new
                {
                    fields = sizes.Fields,
                    pageNumber = sizes.PageNumber + 1,
                    pageSize = sizes.PageSize
                }));

            case ResourceUriType.Current:
            default:
                return(Url.Link("Employees",
                                new
                {
                    fields = sizes.Fields,
                    pageNumber = sizes.PageNumber,
                    pageSize = sizes.PageSize
                }));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Internal method to change the page size accordingly with the size changes in print preview window.
        /// </summary>
        /// <param name="pageHeight"></param>
        /// <param name="pageWidth"></param>
        internal void OnPageSizesChanged(double pageHeight, double pageWidth)
        {
            bool isMatch = false;

            foreach (PrintPageSize pagesize in PageSizes)
            {
                if (PageSettings.PageOrientation == PageOrientation.Portrait)
                {
                    if (pagesize.Size.Height == Math.Round(pageHeight) && pagesize.Size.Width == Math.Round(pageWidth))
                    {
                        PageSize = pagesize;
                        isMatch  = true;
                        break;
                    }
                }
                else if (this.PageSettings.PageOrientation == PageOrientation.Landscape)
                {
                    if (pagesize.Size.Height == Math.Round(pageWidth) && pagesize.Size.Width == Math.Round(pageHeight))
                    {
                        PageSize = pagesize;
                        isMatch  = true;
                        break;
                    }
                }
            }

            if (!isMatch && pageHeight.ToString() != "NaN" && pageWidth.ToString() != "NaN")
            {
                PageSize      = PageSizes.Last();
                PageSize.Size = new Size(pageWidth, pageHeight);
            }
        }
Ejemplo n.º 3
0
        public IActionResult GetEmployees(PageSizes sizes)
        {
            var employees  = data.Employees(sizes);
            var pagingMeta = new
            {
                totalCount  = employees.TotalCount,
                totalPage   = employees.TotalPage,
                currentPage = employees.CurrentPage,
                pageSize    = employees.PageSize
            };

            Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(pagingMeta));
            var link      = CreateEmployeesLink(sizes, employees.HasNext, employees.Hasprevious);
            var addedLink = mapper.Map <IEnumerable <EmployeesDto> >(employees).ShapeData(sizes.Fields) as IDictionary <string, object>;
            var addlink   = addedLink.Select(a =>
            {
                var studentasdictionary = a.ShapeData(sizes.Fields) as IDictionary <string, object>;
                var studentLinks        = CreateEmployeeLink((Guid)studentasdictionary["EmployeeId"], null);
                studentasdictionary.Add("links", studentLinks);
                return(studentasdictionary);
            });
            var linkCollection = new
            {
                value = addlink,
                link
            };

            return(Ok(addedLink));
        }
        /// <summary>
        /// Method to change the number of results displayed per page.
        /// </summary>
        /// <param name="pageSize">
        /// The new page size option.
        /// </param>
        public void ChangePageSize(PageSizes pageSize)
        {
            // Get the ID of the original <table> element.
            // This is overridden and replaced by the third party DataTables widget.
            var id = this.Driver.FindElement(this.Selector).GetAttribute("id");

            // Navigate from the original <table> to the DataTables wrapper of the page size control.
            // The HTML for this control is dynamically injected.
            var wrapper = this.Driver.FindElement(By.Id(string.Format("{0}_length", id)));

            // Get the <select> element which sets the page size.
            var element = new SelectElement(wrapper.FindElement(By.TagName("select")));

            // Select the new page size value.
            switch (pageSize)
            {
            case PageSizes.Ten:
                element.SelectByText("10");
                break;

            case PageSizes.TwentyFive:
                element.SelectByText("25");
                break;

            case PageSizes.Fifty:
                element.SelectByText("50");
                break;

            case PageSizes.Hundred:
                element.SelectByText("100");
                break;
            }
        }
Ejemplo n.º 5
0
        public void SetPageSize(PageSizes pageSize)
        {
            var idx = 0;

            switch (pageSize)
            {
            case PageSizes.Five:
                idx = 0;
                break;

            case PageSizes.Ten:
                idx = 1;
                break;

            case PageSizes.Thirty:
                idx = 2;
                break;

            case PageSizes.Fifty:
                idx = 3;
                break;

            case PageSizes.Hundred:
                idx = 4;
                break;

            default:
                idx = 1;
                break;
            }
            cmbPageSizes.SelectedIndex = idx;
        }
Ejemplo n.º 6
0
        public TPageSettings GetPageSize(PageSizes size, bool Landscape)
        {
            TPageSettings pageSet;

            pageSet.PageType  = size;
            pageSet.Landscape = Landscape;
            pageSet.Height    = 297;
            pageSet.Width     = 210;
            switch (size)
            {
            case PageSizes.A0:
                pageSet.Height = 1189;
                pageSet.Width  = 841;
                break;

            case PageSizes.A1:
                pageSet.Height = 841;
                pageSet.Width  = 594;
                break;

            case PageSizes.A2:
                pageSet.Height = 594;
                pageSet.Width  = 420;
                break;

            case PageSizes.A3:
                pageSet.Height = 420;
                pageSet.Width  = 297;
                break;

            case PageSizes.A5:
                pageSet.Height = 210;
                pageSet.Width  = 148;
                break;

            case PageSizes.A6:
                pageSet.Height = 148;
                pageSet.Width  = 105;
                break;

            case PageSizes.A7:
                pageSet.Height = 105;
                pageSet.Width  = 74;
                break;

            case PageSizes.A8:
                pageSet.Height = 74;
                pageSet.Width  = 52;
                break;
            }

            if (Landscape)
            {
                int x = pageSet.Height;
                pageSet.Height = pageSet.Width;
                pageSet.Width  = x;
            }
            return(pageSet);
        }
Ejemplo n.º 7
0
        public PageList <Employee> Employees(PageSizes sizes)
        {
            var employees = db.Employee.OrderBy(r => r.EmployeeId);

            if (!string.IsNullOrWhiteSpace(sizes.Orderby))
            {
                var employee = propertyMapping.GetPropertyMapping <EmployeesDto, Employee>();
                employees = employees.ApplySort(sizes.Orderby, employee);
            }
            return(PageList <Employee> .Create(employees, sizes.PageNumber, sizes.PageSize));
        }
Ejemplo n.º 8
0
        private void SetDefaultValues()
        {
            ItemsSource = new ObservableCollection <object>();

            PageSizes.Clear();
            PageSizes.Add(10);
            PageSizes.Add(20);
            PageSizes.Add(50);
            PageSizes.Add(100);

            cmbPageSizes.IsEditable    = false;
            cmbPageSizes.SelectedIndex = 0;
        }
Ejemplo n.º 9
0
 public Report(PageSizes PageType = PageSizes.A4, Orientations Orientation = Orientations.Portrait)
 {
     ReportGroups  = new List <ReportGroup>();
     DetailSection = new ReportSection()
     {
         ID = "DetailSection", Height = DefaultDetailHeight
     };
     LeftMargin               = 30; //total width A4 = 594
     RightMargin              = 20;
     TopMargin                = 40;
     BottomMargin             = 20;
     this.SelectedPageType    = PageType;
     this.SelectedOrientation = Orientation;
     DefaultStyle             = Style.Default;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Displays notifications.
        /// </summary>
        /// <param name="app">The Notifications app.</param>
        /// <param name="query">Query object for paging.</param>
        public override ActionResult Get(Notifications app, Query query)
        {
            app.Result = NotificationService.Search(new NotificationQuery(query)
            {
                OrderBy    = "Id DESC",
                SearchRead = null,
                Top        = PageSizes.First()
            });

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Notifications", app.Result));
            }

            return(View(app));
        }
Ejemplo n.º 11
0
        private IEnumerable <LinkDto> CreateEmployeesLink(PageSizes sizes, bool hasNext, bool hasPrevious)
        {
            var links = new List <LinkDto>();

            links.Add(new LinkDto(CreateEmployeeUrl(sizes, ResourceUriType.Current), "self", "GET"));

            if (hasNext)
            {
                links.Add(new LinkDto(CreateEmployeeUrl(sizes, ResourceUriType.Nextpage), "Nextpage", "GET"));
            }
            if (hasPrevious)
            {
                links.Add(new LinkDto(CreateEmployeeUrl(sizes, ResourceUriType.PreviousPage), "Previouspage", "GET"));
            }
            return(links);
        }
Ejemplo n.º 12
0
        private void cmbPageSizes_SelectedIndexChanged(object sender, EventArgs e)
        {
            var oldPageSize = pageSize;

            pageSize = GetPageSize();

            var evt = NotifyPageSizeChanged;

            bool cancel = false;

            if (evt != null)
            {
                evt((int)GetPageSize(), ref cancel);
            }

            if (cancel)
            {
                pageSize = oldPageSize;
            }
        }
Ejemplo n.º 13
0
        protected override void Validate()
        {
            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllFields().Where(f => !f.System))
            {
                if (Constants.InvalidFieldNames.Contains(field.Alias))
                {
                    Error($"{field.Alias} is a reserved word in {Alias}.  Please alias it (<a name='{field.Alias}' alias='{Alias}{field.Alias.Remove(0, 3)}' />).");
                }
            }

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            if (Page > 0 && !PageSizes.Any())
            {
                PageSizes.Add(new PageSize {
                    Size = 10
                });
                PageSizes.Add(new PageSize {
                    Size = 15
                });
                PageSizes.Add(new PageSize {
                    Size = 20
                });
            }
        }
Ejemplo n.º 14
0
        private void BindProperties()
        {
            if (!IsPagingEnable)
            {
                return;
            }
            Binding propBinding;

            propBinding = new Binding(nameof(Page));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.TemplatedParent);
            propBinding.Mode                = BindingMode.TwoWay;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            txtPage.SetBinding(TextBox.TextProperty, propBinding);

            //cmbPageSizes.ItemsSource = null;
            List <int> ps = PageSizes.Distinct().ToList();

            PageSizes.Clear();
            ps.ForEach((i) => { PageSizes.Add(i); });
            propBinding = new Binding(nameof(PageSizes));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.TemplatedParent);
            propBinding.Mode                = BindingMode.OneTime;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            cmbPageSizes.SetBinding(ComboBox.ItemsSourceProperty, propBinding);
            //cmbPageSizes.ItemsSource = new ObservableCollection<int>() {10,50,100,150,200,500,1000};

            propBinding = new Binding(nameof(TotalPages));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.TemplatedParent);
            propBinding.Mode                = BindingMode.TwoWay;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            txtTotalPage.SetBinding(TextBox.TextProperty, propBinding);

            propBinding = new Binding(nameof(ItemsData));
            propBinding.RelativeSource      = new RelativeSource(RelativeSourceMode.Self);
            propBinding.Mode                = BindingMode.TwoWay;
            propBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            SetBinding(ItemsSourceProperty, propBinding);
        }
Ejemplo n.º 15
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (InitialPageSize > 0)
            {
                if (!PageSizes.Contains(InitialPageSize))
                {
                    PageSizes.Add(InitialPageSize);
                }

                _activePageSize = InitialPageSize;
            }

            if (string.IsNullOrEmpty(InitialOrder))
            {
                if (OrderOptions.Count >= 1)
                {
                    _activeOrder = OrderOptions.First().Id;
                }
            }
            else
            {
                _activeOrder = InitialOrder;
            }

            ActionLauncher.OnShowDetailsRequested += ActionLauncher_OnShowDetailsRequested;
            ActionLauncher.OnShowMasterRequested  += ActionLauncher_OnShowMasterRequested;

            if (EventCallbacks != null)
            {
                EventCallbacks.OnFilterStatusChanged += EventCallbacks_OnFilterStatusChanged;
                EventCallbacks.OnStatusHasChanged    += EventCallbacks_OnStatusHasChanged;
                hasEventBinded = true;
            }
        }
Ejemplo n.º 16
0
        public ActionResult Messenger(int?id, QueryOptions opts)
        {
            // limit page size to 25
            opts.Top = Math.Min(opts.Top ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE);

            var model = new Messenger {
                ConversationId = id
            };

            if (model.ConversationId != null)
            {
                // get selected conversation
                model.Conversation = ConversationService.Get(model.ConversationId.Value);
                if (model.Conversation == null)
                {
                    ThrowResponseException(HttpStatusCode.NotFound, $"Conversation with id {model.ConversationId.Value} not found");
                }
            }
            else
            {
                // get most recent conversation
                model.Conversation = ConversationService.Search(new ConversationQuery {
                    OrderBy = "PinnedAt DESC, LastMessageAt DESC", Top = 1
                }).FirstOrDefault();
            }

            if (model.Conversation != null)
            {
                if (model.ConversationId != null)
                {
                    // mark conversation as read (if needed)
                    if (model.Conversation.ReadAt == null)
                    {
                        model.Conversation = ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow);
                    }
                    else if (model.Conversation.ReadAt < model.Conversation.LastMessage?.CreatedAt)
                    {
                        // NOTE: do not assign the read conversation to model.Conversation since that will prevent rendering of the "New messages" separator
                        ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow);
                    }
                }

                // get first page of messages (and reverse them for easier rendering in correct order)
                model.Messages = ConversationService.GetMessages(model.Conversation.Id, new QueryOptions {
                    Top = MAX_PAGE_SIZE
                });
                model.Messages.Reverse();
            }

            // Meetings
            model.ZoomEnabled  = ConfigurationService.ZoomMeetings;
            model.TeamsEnabled = ConfigurationService.TeamsMeetings;

            // NOTE: we load conversations last so that selected conversation does not appear unread in the list
            var query = new ConversationQuery(opts);

            query.UserId        = User.Id;
            query.OrderBy       = "PinnedAt DESC, LastMessageAt DESC";
            model.Conversations = ConversationService.Search(query);

            // make sure selected conversation is visible in conversations list
            while (model.Conversation != null && !model.Conversations.Any(x => x.Id == model.Conversation.Id))
            {
                query.Top          += PageSizes.First();
                model.Conversations = ConversationService.Search(query);
            }

            return(View(nameof(Messenger), model));
        }
Ejemplo n.º 17
0
        protected override void Validate()
        {
            // if validation has been defined, check to see if corresponding valid and message fields are present and create them if not
            var calculatedKeys = new HashSet <string>(CalculatedFields.Select(f => f.Alias ?? f.Name).Distinct(), StringComparer.OrdinalIgnoreCase);

            if (Fields.Any(f => f.Validators.Any()))
            {
                foreach (var field in Fields.Where(f => f.Validators.Any()))
                {
                    if (!calculatedKeys.Contains(field.ValidField))
                    {
                        CalculatedFields.Add(new Field {
                            Name         = field.ValidField,
                            Alias        = field.ValidField,
                            Input        = false,
                            Type         = "bool",
                            Default      = "true",
                            IsCalculated = true
                        });
                    }

                    if (!calculatedKeys.Contains(field.MessageField))
                    {
                        CalculatedFields.Add(new Field {
                            Name = field.MessageField, Alias = field.MessageField, Length = "255", Default = "", IsCalculated = true, Input = false
                        });
                    }
                }
                // create an entity-wide valid field if necessary
                if (ValidField == string.Empty)
                {
                    var valid = Alias + "Valid";
                    if (!CalculatedFields.Any(f => f.Name.Equals(valid)))
                    {
                        var add = new Field {
                            Name = valid, Alias = valid, Type = "bool", ValidField = valid, Input = false, IsCalculated = true
                        };
                        add.Validators.Add(new Operation {
                            Method     = "all",
                            Operator   = "equals",
                            Value      = "true",
                            Parameters = GetAllFields().Where(f => f.ValidField != string.Empty).Select(f => f.ValidField).Distinct().Select(n => new Parameter {
                                Field = n
                            }).ToList()
                        });
                        CalculatedFields.Add(add);
                        ValidField = valid;
                    }
                }
            }

            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            // Paging Madness
            if (Page > 0)
            {
                if (PageSizes.Any())
                {
                    if (PageSizes.All(ps => ps.Size != PageSize))
                    {
                        var first = PageSizes.First().Size;
                        Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}.");
                        PageSize = first;
                    }
                }
                else
                {
                    if (PageSize > 0)
                    {
                        PageSizes.Add(new PageSize {
                            Size = PageSize
                        });
                    }
                    else
                    {
                        PageSizes.Add(new PageSize {
                            Size = 25
                        });
                        PageSizes.Add(new PageSize {
                            Size = 50
                        });
                        PageSizes.Add(new PageSize {
                            Size = 100
                        });
                        if (PageSize != 25 && PageSize != 50 && PageSize != 100)
                        {
                            PageSize = 25;
                        }
                    }
                }
            }
            else
            {
                if (PageSize > 0)
                {
                    PageSize = 0;
                }
            }
        }
Ejemplo n.º 18
0
 public Document(string documentType, PageSizes pageSize, TimeSpan timeToPrint)
 {
     DocumentType = documentType;
     PageSize     = pageSize;
     TimeToPrint  = timeToPrint;
 }
Ejemplo n.º 19
0
        protected override void Validate()
        {
            var fields  = GetAllFields().ToArray();
            var names   = new HashSet <string>(fields.Select(f => f.Name).Distinct());
            var aliases = new HashSet <string>(fields.Select(f => f.Alias));

            ValidateVersion(names, aliases);
            ValidateFilter(names, aliases);
            ValidateOrder(names, aliases);

            foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField)))
            {
                if (GetField(field.SortField) == null)
                {
                    Error($"Can't find sort field {field.SortField} defined in field {field.Alias}.");
                }
            }

            // Paging Madness
            if (Page > 0)
            {
                if (PageSizes.Any())
                {
                    if (PageSizes.All(ps => ps.Size != PageSize))
                    {
                        var first = PageSizes.First().Size;
                        Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}.");
                        PageSize = first;
                    }
                }
                else
                {
                    if (PageSize > 0)
                    {
                        PageSizes.Add(new PageSize {
                            Size = PageSize
                        });
                    }
                    else
                    {
                        PageSizes.Add(new PageSize {
                            Size = 25
                        });
                        PageSizes.Add(new PageSize {
                            Size = 50
                        });
                        PageSizes.Add(new PageSize {
                            Size = 100
                        });
                        if (PageSize != 25 && PageSize != 50 && PageSize != 100)
                        {
                            PageSize = 25;
                        }
                    }
                }
            }
            else
            {
                if (PageSize > 0)
                {
                    PageSize = 0;
                }
            }
        }
Ejemplo n.º 20
0
 public ContinuationFormViewModel()
 {
     PageSizes = new[] { 10, 20, 30, 40, 50 };
     PageSize  = PageSizes.Last();
 }
Ejemplo n.º 21
0
        protected void WriteHtml(HtmlTextWriter writer)
        {
            var jsName = this.Name.Replace("-", "__");

            // create the table
            writer.WriteLine(String.Format("<table id=\"{0}\" class=\"table table-striped table-bordered\" cellspacing=\"0\" width=\"100%\"></table>", this.Name));

            int index = 0;

            foreach (var col in this.Columns)
            {
                col.Index = index++;
            }

            // if we're serializing data, write it out here...
            // TODO, limit the serializaton to the bound columns
            if (this.DataSource != null)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Script);
                // TODO, convert this object, it will need to add orthagonal data, and handle custom column rendering
                List <Dictionary <string, dynamic> > processed = new List <Dictionary <string, object> >();
                foreach (var row in this.DataSource)
                {
                    Dictionary <string, dynamic> addRow = new Dictionary <string, dynamic>();
                    foreach (var col in this.Columns)
                    {
                        if (col.ColumnType == ColumnType.Render || col.ColumnType == ColumnType.Button)
                        {
                            continue;
                        }
                        else
                        {
                            string val = getPropertyValue(row, col);
                            if (!String.IsNullOrWhiteSpace(col.Template))
                            {
                                addRow.Add("CustomColumn_" + col.Index.ToString(), val);
                            }
                            else
                            {
                                Type t = row.GetType().GetProperty(col.Member).PropertyType;
                                if (t == typeof(DateTime))
                                {
                                    // going to send orthogonal
                                    DateTime realVal = (DateTime)row.GetType().GetProperty(col.Member).GetValue(row, null);
                                    addRow.Add(col.Member, new { display = val, timestamp = realVal.ToString("yyyyMMddhhmmss") });
                                }
                                else
                                {
                                    addRow.Add(col.Member, val);
                                }
                            }
                        }
                    }
                    processed.Add(addRow);
                }


                writer.WriteLine("var " + jsName + "_Data = " + Json.Encode(processed));
                writer.RenderEndTag();
            }

            // begin creating the datatable initialiaztion script
            writer.RenderBeginTag(HtmlTextWriterTag.Script);
            writer.WriteLine(String.Format("$(document).ready(function () {{ var {1} = $('#{0}').DataTable({{", this.Name, jsName));

            if (this.Paginate || this.Clean)
            {
                // paging type
                if (PagingType != PagingType.simple_numbers)
                {
                    writer.WriteLine("pagingType: '" + PagingType.ToString() + "',");
                }

                // page sizes
                if (PageSizes != null && PageSizes.Count() > 0)
                {
                    writer.Write("lengthMenu: [[");
                    writer.Write(string.Join(",", PageSizes));
                    writer.Write("],[");
                    writer.Write(string.Join(",", PageSizes).Replace("-1", "'All'"));
                    writer.WriteLine("]],");
                }

                // page size
                if (PageSize != 0)
                {
                    writer.WriteLine("displayLength: " + PageSize + ",");
                }
            }
            else
            {
                writer.WriteLine("paging: false,");
            }

            if (this.Clean)
            {
                writer.WriteLine("sDom: 't',");
            }

            // ScrollX
            if (ScrollX || Freeze > 0)
            {
                writer.WriteLine("scrollX: true,");
            }

            // ScrollY
            if (!String.IsNullOrEmpty(ScrollY))
            {
                writer.WriteLine("scrollY: '" + ScrollY + "',");
                writer.WriteLine("scrollCollapse: true,");
            }

            writer.WriteLine("columns: [");

            StringBuilder dataMethods = new StringBuilder();
            int           colIndex    = 0;

            // loop through the columns
            foreach (var c in this.Columns)
            {
                c.Index = colIndex;
                c.ProcessResponsive();

                writer.Write("{");

                if (c.ColumnType == ColumnType.Bound)
                {
                    #region Bound
                    if (String.IsNullOrEmpty(c.Title))
                    {
                        c.Title = StringHelper.SplitPascalCase(c.Member);
                    }

                    if (c.Type == typeof(DateTime))
                    {
                        writer.Write(string.Format(" data: \"{0}.display\", sort: \"{0}.timestamp\", ", c.Member));
                    }
                    else
                    {
                        writer.Write(String.Format(" data: \"{0}\", ", c.Member));
                    }

                    if (c.Width > 0)
                    {
                        writer.Write(string.Format("width: {0}, ", c.Width));
                    }


                    writer.Write(string.Format("title: \"{0}\", ", c.Title));
                    if (!String.IsNullOrEmpty(c.Format))
                    {
                        dataMethods.AppendLine(String.Format("d.columns[{0}][\"format\"] = '{1}';", colIndex, c.Format));
                    }
                    if (!String.IsNullOrWhiteSpace(c.Render))
                    {
                        writer.Write(String.Format("render: {0}, ", c.Render));
                    }
                    // var x = typeof(T).GetProperty(c.Member).PropertyType.Name;
                    #endregion
                }
                else if (c.ColumnType == ColumnType.Custom)
                {
                    #region Custom
                    c.Member = "CustomColumn_" + colIndex.ToString();
                    if (String.IsNullOrEmpty(c.Title))
                    {
                        c.Title = "Custom";
                    }
                    writer.Write(String.Format(" data: \"{0}\", title: \"{1}\", ", c.Member, c.Title));
                    // c.Searchable = false;
                    // c.Sortable = false;

                    dataMethods.AppendLine(String.Format("d.columns[{0}][\"template\"] = '{1}';", colIndex, HttpUtility.HtmlEncode(c.Template)));

                    #endregion
                }
                else if (c.ColumnType == ColumnType.Render)
                {
                    #region Render
                    var rc = (RenderColumn <T>)c;
                    if (String.IsNullOrEmpty(c.Title))
                    {
                        c.Title = "Render";
                    }
                    writer.Write(String.Format(" render: {0}, title: \"{1}\", ", rc.RenderMethod, c.Title));
                    #endregion
                }
                else if (c.ColumnType == ColumnType.Button)
                {
                    #region Button
                    List <dynamic> buttonDefs = new List <dynamic>();
                    foreach (var b in ((ButtonColumn <T>)c).Buttons)
                    {
                        buttonDefs.Add(b);
                    }
                    string renderJs = string.Format("function (data, type, row) {{ return talondatatable_renderbuttons(row, {0}); }}", Json.Encode(buttonDefs));
                    // addRow.Add("ButtonColumn_" + col.Index.ToString(), buttonDefs);
                    writer.Write(String.Format(" data: \"ButtonColumn_{0}\", title: \"{1}\", render: {2}, ", c.Index, c.Title, renderJs));
                    #endregion
                }

                if (!String.IsNullOrEmpty(c.ClassName))
                {
                    writer.Write(String.Format("className: \"{0}\", ", c.ClassName));
                }
                if (c.Hidden)
                {
                    writer.Write("visible: false, ");
                }
                if (c.Width > 0)
                {
                    writer.Write(String.Format("width: {0}, ", c.Width));
                }
                if (!c.Searchable)
                {
                    writer.Write("searchable: false, ");
                }
                if (!c.Sortable)
                {
                    writer.Write("sortable: false, ");
                }

                writer.WriteLine("},");

                colIndex++;
            }
            // finish the initialization script
            writer.WriteLine("],");

            var orders = this.Columns.Where(c => c.SortOrder > 0);

            if (orders.Count() > 0)
            {
                writer.Write("order: [");
                foreach (var col in orders.OrderBy(o => o.SortOrder))
                {
                    writer.Write("[ " + col.Index + ", '" + col.SortDirection.ToString() + "' ],");
                }
                writer.WriteLine("],");
            }

            if (this.DataSource != null)
            {
                writer.WriteLine("data: " + jsName + "_Data,");
            }
            else if (!String.IsNullOrEmpty(this.AjaxSource))
            {
                writer.WriteLine("processing: true, serverSide: true, searchDelay: 750, ajax: {");
                writer.WriteLine("url: \"" + this.AjaxSource + "\", type: \"POST\",");
                if (dataMethods.Length > 0)
                {
                    writer.WriteLine("data: function(d) {");
                    writer.WriteLine(dataMethods.ToString());
                    writer.WriteLine("}");
                }
                writer.WriteLine(" },");
            }

            writer.WriteLine("});");

            if (Freeze > 0)
            {
                writer.WriteLine(String.Format("new $.fn.dataTable.FixedColumns( {0}, {{ leftColumns: {1} }});", jsName, Freeze));
            }

            writer.WriteLine(String.Format("$('#{0}').data('datatable', {1});", this.Name, jsName));

            writer.WriteLine("});");

            writer.RenderEndTag();
        }
Ejemplo n.º 22
0
 public Grid <T> DefaultPageSize(PageSizes pageSizes)
 {
     GridModel.Pagination.PageSize = (int)pageSizes;
     return(this);
 }