Skip to content

Commit

Permalink
Add AutoFill command
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Sep 24, 2023
1 parent d834685 commit bb584e0
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 105 deletions.
33 changes: 14 additions & 19 deletions Samples/TableBasicSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// The maintenance and evolution is maintained by the PromptPlus project under MIT license
// ***************************************************************************************

using System.ComponentModel;
using System.Globalization;
using PPlus;
using PPlus.Controls;
Expand Down Expand Up @@ -38,7 +39,7 @@ static MyTable[] CreateItems()
var result = new List<MyTable>();
var flag = false;
result.Add(new MyTable { Id = 0, MyDate = new DateTime(), MyText = $"Test0 linha1{Environment.NewLine}Test3 linha2", ComplexCol = new MyComplexCol("C0") });
for (int i = 1; i < 15; i++)
for (int i = 1; i < 19; i++)
{
flag = !flag;
if (flag)
Expand All @@ -65,22 +66,22 @@ static MyTable[] CreateItems()
//.Default(data[1])
//.ChangeDescription((item,row,col) => $"{item.ComplexCol.Name}")
//.PageSize(6)
.EnableColumnsNavigation()
.WithSeparatorRows()
.FilterByColumns(FilterMode.Contains, 1, 4)
.Layout(TableLayout.SingleGridFull)
.Title("Test", titleMode: TableTitleMode.InRow)
//.ColumnsNavigation()
//.SeparatorRows()
//.FilterByColumns(FilterMode.Contains, 1, 4)
//.Layout(TableLayout.SingleGridFull)
//.Title("Test", titleMode: TableTitleMode.InRow)
.AddItems(data)
.AddItem(new MyTable { Id = data.Length, MyText = $"Test{data.Length} disabled", ComplexCol = new MyComplexCol($"C{data.Length}") }, true)
.AddColumn(field: (item) => item.Id, width: 10)
.AddColumn(field: (item) => item.MyDate!, width: 15/*,alignment: Alignment.Center*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text: {arg}", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.ComplexCol, width: 20, format: (arg) => $"{((MyComplexCol)arg).Id}:{((MyComplexCol)arg).Name}")
.AddColumn(field: (item) => item.ComplexCol.Name, width: 10)
.AutoFill()
//.AddColumn(field: (item) => item.Id, width: 10)
//.AddColumn(field: (item) => item.MyDate!, width: 15/*,alignment: Alignment.Center*/)
//.AddColumn(field: (item) => item.MyText, width: 120, format: (arg) => $"Text: {arg}", maxslidinglines: 5/*, textcrop:true*/)
//.AddColumn(field: (item) => item.ComplexCol, width: 20, format: (arg) => $"{((MyComplexCol)arg).Id}:{((MyComplexCol)arg).Name}")
//.AddColumn(field: (item) => item.ComplexCol.Name, width: 10)
//.AutoFit(1,2)
.AddFormatType<DateTime>(FmtDate)
.AddFormatType<int>(FmtInt)
.EnabledInteractionUser(
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
finishTemplate: (item, row, col) => $"[green]Selected ID : {item.Id}. Current row {row}, Current col {col}[/]")
.Run();
Expand All @@ -91,12 +92,6 @@ static MyTable[] CreateItems()
Console.ReadKey();
}

private static string FmtInt(object arg)
{
var value = (int)arg;
return value.ToString();
}

private static string FmtDate(object arg)
{
var value = (DateTime)arg;
Expand Down
20 changes: 16 additions & 4 deletions Src/Controls/Table/IControlTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
IControlTable<T> Interaction<T1>(IEnumerable<T1> values, Action<IControlTable<T>, T1> action);

/// <summary>
/// Set max.item view per page.Default value for this control is 5.
/// Set max.item view per page.Default value for this control is 10.
/// </summary>
/// <param name="value">Number of Max.rows</param>
/// <returns><see cref="IControlTable{T}"/></returns>
Expand Down Expand Up @@ -157,11 +157,23 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AddColumn(Expression < Func<T, object>> field, ushort width, Func<object, string> format = null,Alignment alignment = Alignment.Left, string? title = null, Alignment titlealignment = Alignment.Center,bool titlereplaceswidth = true, bool textcrop = false, int? maxslidinglines = null);

/// <summary>
/// Auto generate Columns
/// <br>Header alignment will always be 'Center' </br>
/// <br>The content alignment will always be 'Left' </br>
/// <br>The content will always be with sliding lines</br>
/// <br>Columns are generated by the public properties of the data class recognized by <see cref="TypeCode"/>.</br>
/// <br>TypeCode.DBNull and TypeCode.Object will be ignored.</br>
/// <br>The table size will automatically adjust according to the size of the column content to the width of the screen</br>
/// </summary>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AutoFill();

/// <summary>
/// Set separator between rows. Default none.
/// </summary>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> WithSeparatorRows();
IControlTable<T> SeparatorRows();

/// <summary>
/// Hide columns headers. Default false.
Expand Down Expand Up @@ -206,13 +218,13 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// </param>
/// <param name="removetable">True not write table, otherwise write last state of table</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> EnabledInteractionUser(Func<T, int, int, string> selectedTemplate = null, Func<T, int, int, string> finishTemplate = null, bool removetable = true);
IControlTable<T> UserInteraction(Func<T, int, int, string> selectedTemplate = null, Func<T, int, int, string> finishTemplate = null, bool removetable = true);

/// <summary>
/// Enable Columns Navigation. Default, Rows Navigation.
/// </summary>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> EnableColumnsNavigation();
IControlTable<T> ColumnsNavigation();

}
}
Loading

0 comments on commit bb584e0

Please sign in to comment.