Add advanced builders for search and buttons in DataTables - #30
Conversation
Detailed configuration methods are added for Search and button collections (CollectionButton) in the DataTables builders. Includes new classes SearchingBuilder, CollectionButtonBuilder, LayoutOptionsBuilder, LayoutOptions, and Searching for advanced search and layout options. The DatatableJs model now supports the Search property. The example in Index.cshtml is updated to show advanced layouts with buttons and custom search.
| public LayoutOptionsBuilder Buttons(params string[] buttons) | ||
| { | ||
| _options.Buttons.Add(buttons); | ||
| return this; |
There was a problem hiding this comment.
Dereferences a null list in Buttons(params string[] buttons). LayoutsBuilder.Position() creates a fresh LayoutOptions, and its Buttons field starts as null LayoutOptions.cs (line 14). The PR’s sample uses this path directly in Index.cshtml (line 68), so top.Buttons("selectAll", "selectNone") will throw a server-side NullReferenceException before the page renders. Even if the list were initialized, _options.Buttons.Add(buttons) would serialize as a nested array, while DataTables expects a flat buttons list.
| { | ||
| public bool Return { get; set; } | ||
| public string Placeholder { get; set; } = default; | ||
| public bool Boundary { get; set; } = false; |
There was a problem hiding this comment.
Searching.cs (line 14) models smart and caseInsensitive as non-nullable bool values defaulting to false. The serializer only ignores null values RKHelperExtensions.cs (line 133), so even a minimal search config such as the new placeholder example in Index.cshtml (line 82) will emit smart:false and caseInsensitive:false. That silently changes DataTables’ default search behavior.
Default values are true:
https://datatables.net/reference/option/search.smart and https://datatables.net/reference/option/search.caseInsensitive
| public SearchingBuilder Regex(string regex) | ||
| { | ||
| _search.Regex = regex; | ||
| return this; |
There was a problem hiding this comment.
SearchingBuilder.cs (line 37) and Searching.cs (line 19) model search.regex as a string, but DataTables expects a boolean. With the current API, callers cannot produce the correct shape like regex: true; they can only emit string values.
https://datatables.net/reference/option/search.regex
Detailed configuration methods are added for Search and button collections (CollectionButton) in the DataTables builders. Includes new classes SearchingBuilder, CollectionButtonBuilder, LayoutOptionsBuilder, LayoutOptions, and Searching for advanced search and layout options. The DatatableJs model now supports the Search property. The example in Index.cshtml is updated to show advanced layouts with buttons and custom search.
Output: