public void UpdateDisplay() { if (Ref_InputField != null && Ref_InputFieldContainer != null && Ref_InputFieldToggleButtonCell != null) { UpdateInputFieldText(); var valueBefore = Ref_InputFieldContainer.ColumnWidths.ToList(); if (InputFieldConfig.ShowToggleButton) { Ref_InputFieldContainer.ColumnWidths = new List <float> { 0, InputFieldConfig.ToggleButtonWidth }; Ref_InputFieldToggleButtonCell.gameObject.SetActive(true); } else { Ref_InputFieldContainer.ColumnWidths = new List <float> { 0 }; Ref_InputFieldToggleButtonCell.gameObject.SetActive(false); } if (!valueBefore.SequenceEqual(Ref_InputFieldContainer.ColumnWidths)) { Ref_InputFieldContainer.UpdateLayout(); } } }
private void orderTableByColumValue(TableLayout table, int colNum) { TableLayout tempTable = table; Dictionary <int, float> rowsToColValues = new Dictionary <int, float>(); for (int i = 0; i < table.Rows.Count; i++) { TableRow currentRow = table.Rows[i]; string stringValue = currentRow.Cells[colNum].GetComponentInChildren <Text>().text; float floatValue = float.Parse(stringValue, CultureInfo.InvariantCulture.NumberFormat); // int intValue = (int)Math.Floor(floatValue); rowsToColValues[i] = floatValue; } Dictionary <int, int> rowMapper = new Dictionary <int, int>(); var ordered = rowsToColValues.OrderBy(x => x.Value); int index = 0; foreach (var item in ordered) { rowMapper[index] = item.Key; index++; } table.ClearRows(); for (int i = 0; i < tempTable.Rows.Count; i++) { table.Rows[i] = tempTable.Rows[rowMapper[i]]; } // Destroy(tempTable); table.CalculateLayoutInputVertical(); table.UpdateLayout(); }
private void sortTableByType() { if (!typeHeaderSortedAsscending) { Debug.Log("A"); tableLayout = orderTableByColumValue(tableLayout, 0, false); typeHeaderSortedAsscending = true; typeSort.sprite = Resources.Load("Sprites/sort_down", typeof(Sprite)) as Sprite; } else { Debug.Log("B"); tableLayout = orderTableByColumValue(tableLayout, 0, true); typeHeaderSortedAsscending = false; typeSort.sprite = Resources.Load("Sprites/sort_up", typeof(Sprite)) as Sprite; } tableLayout.UpdateLayout(); }
public void UpdateDisplay() { // don't do anything if we aren't actually active in the hierarchy // (basically, we're either inactive or a prefab) if (!this.gameObject.activeInHierarchy) { return; } if (Config.Sizing.OverrideTransformHeight) { Ref_DatePickerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Config.Sizing.PreferredHeight); } UpdateBorder(); UpdateHeader(); UpdateWeekDayHeaders(); UpdateDaySection(); // Free all buttons in the pool buttonPool.FreeAll(); // Clear existing data Ref_DayTable.ClearRows(); // Day Names var dayNameRow = Ref_DayTable.AddRow(0); dayNameRow.dontUseTableRowBackground = true; // Empty cell if we're showing the Week Numbers column if (Config.WeekDays.ShowWeekNumbers) { var header = Instantiate(Ref_Template_DayName); dayNameRow.AddCell(header.Cell); Ref_DayTable.ColumnWidths[0] = Config.WeekDays.WeekNumberColumnWidth; } else { Ref_DayTable.ColumnWidths[0] = 0; } var dayNames = DatePickerUtilities.GetAbbreviatedDayNames(); foreach (var dayName in dayNames) { var header = Instantiate(Ref_Template_DayName); dayNameRow.AddCell(header.Cell); header.HeaderText.text = dayName; } // Validate our Date Range (if necessary. This method will output an error message if we fail) bool dateRangeValid = Config.DateRange.Validate(); // Dates var days = DatePickerUtilities.GetDateRangeForDisplay(VisibleDate.Date); TableRow row = null; int weekNumber = 1; DateTimeFormatInfo currentDateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo; foreach (var day in days) { if (day.DayOfWeek == DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) { row = Ref_DayTable.AddRow(0); if (Config.WeekDays.ShowWeekNumbers) { if (Config.WeekDays.WeekNumberMode == WeekNumberMode.WeekOfYear) { weekNumber = currentDateTimeFormatInfo.Calendar.GetWeekOfYear(day, Config.WeekDays.CalendarWeekRule, currentDateTimeFormatInfo.FirstDayOfWeek); } var weekNumberCell = Instantiate(Ref_Template_DayName); row.AddCell(weekNumberCell.Cell); weekNumberCell.HeaderText.text = weekNumber.ToString(); weekNumber++; } } if (!Config.Misc.ShowDatesInOtherMonths && !DatePickerUtilities.DateFallsWithinMonth(day, VisibleDate)) { // add an empty cell row.AddCell(); } else { var dayType = GetDayTypeForDate(day); var dayItem = buttonPool.GetButton(dayType); //var dayItem = Instantiate(GetDayTemplateForDate(day)); row.AddCell(dayItem.Cell); dayItem.Text.text = day.Day.ToString(); dayItem.DatePicker = this; dayItem.Date = day; dayItem.name = day.ToDateString(); dayItem.IsTemplate = false; dayItem.Button.interactable = true; if (dateRangeValid) // if the date range is not valid, then don't attempt to use it { if ((Config.DateRange.RestrictFromDate && day.CompareTo(Config.DateRange.FromDate) < 0) || (Config.DateRange.RestrictToDate && day.CompareTo(Config.DateRange.ToDate) > 0)) { dayItem.Button.interactable = false; } } } } if (Ref_InputField != null && Ref_InputFieldContainer != null && Ref_InputFieldToggleButtonCell != null) { Ref_InputField.text = SelectedDate.HasValue ? SelectedDate.Date.ToString(Config.Format.DateFormat) : ""; if (Ref_ScreenOverlay != null) { Ref_ScreenOverlay.color = Config.Modal.ScreenOverlayColor; } var valueBefore = Ref_InputFieldContainer.ColumnWidths.ToList(); if (Config.InputField.ShowToggleButton) { Ref_InputFieldContainer.ColumnWidths = new List <float> { 0, Config.InputField.ToggleButtonWidth }; Ref_InputFieldToggleButtonCell.gameObject.SetActive(true); } else { Ref_InputFieldContainer.ColumnWidths = new List <float> { 0 }; Ref_InputFieldToggleButtonCell.gameObject.SetActive(false); } if (!valueBefore.SequenceEqual(Ref_InputFieldContainer.ColumnWidths)) { Ref_InputFieldContainer.UpdateLayout(); } } }