Skip to content

Commit f397857

Browse files
committed
Added Language Builder
1 parent 4a912c7 commit f397857

File tree

12 files changed

+821
-164
lines changed

12 files changed

+821
-164
lines changed

DatatableJS.Net/Builders/GridBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class GridBuilder<T>
2424
internal string _captionTop { get; private set; }
2525
internal string _captionBottom { get; private set; }
2626
internal bool _paging { get; private set; } = true;
27-
internal string _langUrl { get; private set; }
2827
internal bool _columnSearching { get; private set; }
2928
internal string _columnSearchingCss { get; private set; }
3029
internal List<int> _lengthMenuValues { get; private set; } = new List<int>();
@@ -45,6 +44,7 @@ public class GridBuilder<T>
4544
internal List<OrderDefinition> _orders = new List<OrderDefinition>();
4645

4746
internal CallbackModel _callBack = new CallbackModel();
47+
internal LanguageModel _language = new LanguageModel();
4848

4949
/// <summary>
5050
/// Default name is "DataGrid".
@@ -265,7 +265,7 @@ public GridBuilder<T> Paging(bool paging)
265265
/// <returns></returns>
266266
public GridBuilder<T> Language(string url)
267267
{
268-
_langUrl = url;
268+
_language.URL = url;
269269
return this;
270270
}
271271

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
namespace DatatableJS.Net
2+
{
3+
/// <summary>
4+
/// Generic language builder class
5+
/// </summary>
6+
/// <typeparam name="T"></typeparam>
7+
public class LanguageBuilder<T>
8+
{
9+
private readonly GridBuilder<T> _grid;
10+
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="LanguageBuilder{T}"/> class.
13+
/// </summary>
14+
/// <param name="grid"></param>
15+
public LanguageBuilder(GridBuilder<T> grid)
16+
{
17+
_grid = grid;
18+
}
19+
20+
/// <summary>
21+
/// Set the decimal place character. <see href="https://datatables.net/reference/option/language.decimal">Reference:</see>
22+
/// </summary>
23+
/// <param name="place"></param>
24+
/// <returns></returns>
25+
public LanguageBuilder<T> Decimal(string place)
26+
{
27+
_grid._language.Decimal = place;
28+
return this;
29+
}
30+
31+
/// <summary>
32+
/// This string is shown when the table is empty of data (regardless of filtering). <see href="https://datatables.net/reference/option/language.emptyTable">Reference:</see>
33+
/// </summary>
34+
/// <param name="message">No data available in table</param>
35+
/// <returns></returns>
36+
public LanguageBuilder<T> EmptyTable(string message)
37+
{
38+
_grid._language.EmptyTable = message;
39+
return this;
40+
}
41+
42+
/// <summary>
43+
/// This string gives information to the end user about the information that is current on display on the page. <see href="https://datatables.net/reference/option/language.info">Reference:</see>
44+
/// </summary>
45+
/// <param name="message">Showing _START_ to _END_ of _TOTAL_ entries</param>
46+
/// <returns></returns>
47+
public LanguageBuilder<T> Info(string message)
48+
{
49+
_grid._language.Info = message;
50+
return this;
51+
}
52+
53+
/// <summary>
54+
/// Display information string for when the table is empty. <see href="https://datatables.net/reference/option/language.infoEmpty">Reference:</see>
55+
/// </summary>
56+
/// <param name="message">Showing 0 to 0 of 0 entries</param>
57+
/// <returns></returns>
58+
public LanguageBuilder<T> InfoEmpty(string message)
59+
{
60+
_grid._language.InfoEmpty = message;
61+
return this;
62+
}
63+
64+
/// <summary>
65+
/// When a user filters the information in a table, this string is appended to the information (info) to give an idea of how strong the filtering is. <see href="https://datatables.net/reference/option/language.infoFiltered">Reference:</see>
66+
/// </summary>
67+
/// <param name="message">(filtered from _MAX_ total entries)</param>
68+
/// <returns></returns>
69+
public LanguageBuilder<T> InfoFiltered(string message)
70+
{
71+
_grid._language.InfoFiltered = message;
72+
return this;
73+
}
74+
75+
/// <summary>
76+
/// If can be useful to append extra information to the info string at times, and this variable does exactly that. <see href="https://datatables.net/reference/option/language.infoPostFix">Reference:</see>
77+
/// </summary>
78+
/// <param name="message"></param>
79+
/// <returns></returns>
80+
public LanguageBuilder<T> InfoPostFix(string message)
81+
{
82+
_grid._language.InfoPostFix = message;
83+
return this;
84+
}
85+
86+
/// <summary>
87+
/// The thousands separator option is used for output of information only. <see href="https://datatables.net/reference/option/language.thousands">Reference:</see>
88+
/// </summary>
89+
/// <param name="place">,</param>
90+
/// <returns></returns>
91+
public LanguageBuilder<T> Thousands(string place)
92+
{
93+
_grid._language.Thousands = place;
94+
return this;
95+
}
96+
97+
/// <summary>
98+
/// Detail the action that will be taken when the drop down menu for the pagination length option is changed. <see href="https://datatables.net/reference/option/language.lengthMenu">Reference:</see>
99+
/// </summary>
100+
/// <param name="message">Show _MENU_ entries</param>
101+
/// <returns></returns>
102+
public LanguageBuilder<T> LengthMenu(string message)
103+
{
104+
_grid._language.LengthMenu = message;
105+
return this;
106+
}
107+
108+
/// <summary>
109+
/// This message is shown in an empty row in the table to indicate to the end user the the data is being loaded. <see href="https://datatables.net/reference/option/language.loadingRecords">Reference:</see>
110+
/// </summary>
111+
/// <param name="message">Loading...</param>
112+
/// <returns></returns>
113+
public LanguageBuilder<T> LoadingRecords(string message)
114+
{
115+
_grid._language.LoadingRecords = message;
116+
return this;
117+
}
118+
119+
/// <summary>
120+
/// Text that is displayed when the table is processing a user action (usually a sort command or similar). <see href="https://datatables.net/reference/option/language.processing">Reference:</see>
121+
/// </summary>
122+
/// <param name="message">{Empty string}</param>
123+
/// <returns></returns>
124+
public LanguageBuilder<T> Processing(string message)
125+
{
126+
_grid._language.Processing = message;
127+
return this;
128+
}
129+
130+
/// <summary>
131+
/// Sets the string that is used for DataTables filtering input control. <see href="https://datatables.net/reference/option/language.search">Reference:</see>
132+
/// </summary>
133+
/// <param name="message">Search:</param>
134+
/// <returns></returns>
135+
public LanguageBuilder<T> Search(string message)
136+
{
137+
_grid._language.Search = message;
138+
return this;
139+
}
140+
141+
/// <summary>
142+
/// Text shown inside the table records when the is no information to be displayed after filtering. <see href="https://datatables.net/reference/option/language.zeroRecords">Reference:</see>
143+
/// </summary>
144+
/// <param name="message">No matching records found</param>
145+
/// <returns></returns>
146+
public LanguageBuilder<T> ZeroRecords(string message)
147+
{
148+
_grid._language.ZeroRecords = message;
149+
return this;
150+
}
151+
152+
/// <summary>
153+
/// Pagination string used by DataTables for the built-in pagination control types. <see href="https://datatables.net/reference/option/language.paginate">Reference:</see>
154+
/// </summary>
155+
/// <param name="first">First</param>
156+
/// <param name="last">Last</param>
157+
/// <param name="next">Next</param>
158+
/// <param name="previous">Previous</param>
159+
/// <returns></returns>
160+
public LanguageBuilder<T> Paginate(string first, string last, string next, string previous)
161+
{
162+
_grid._language.Paginate.First = first;
163+
_grid._language.Paginate.Last = last;
164+
_grid._language.Paginate.Next = next;
165+
_grid._language.Paginate.Previous = previous;
166+
return this;
167+
}
168+
169+
/// <summary>
170+
/// Language strings used for WAI-ARIA specific attributes. <see href="https://datatables.net/reference/option/language.aria">Reference:</see>
171+
/// </summary>
172+
/// <param name="sortAscending">: activate to sort column ascending</param>
173+
/// <param name="sortDescending">: activate to sort column descending</param>
174+
/// <returns></returns>
175+
public LanguageBuilder<T> Aria(string sortAscending, string sortDescending)
176+
{
177+
_grid._language.Aria.SortAscending = sortAscending;
178+
_grid._language.Aria.SortDescending = sortDescending;
179+
return this;
180+
}
181+
}
182+
}

0 commit comments

Comments
 (0)