Skip to content

Add advanced builders for search and buttons in DataTables - #30

Open
wlady2906 wants to merge 1 commit into
ekondur:mainfrom
wlady2906:dev-layout-options-and-search-options
Open

Add advanced builders for search and buttons in DataTables#30
wlady2906 wants to merge 1 commit into
ekondur:mainfrom
wlady2906:dev-layout-options-and-search-options

Conversation

@wlady2906

Copy link
Copy Markdown

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.

//index.cshtml
.Layout(x =>
        {
            x.Position("topStart", top =>
            {
                top.Button(btn => btn.Text("Custom button").Action(@$"function(){{ alert('hello from layout options')}}"));
                top.Buttons("selectAll", "selectNone");
                top.Button(btn => btn.Text("Page length").Extend("pageLength"));
                top.Button(btn => btn.Text("Column visibility").Extend("colvis"));
                top.Button(btn =>
                {
                    btn.Text("Custom Export").Extend("collection").Buttons(btn =>
                    {
                        btn.Button(p => p.Text("PDF"));
                        btn.Button(p => p.Text("Excel"));
                    });
                });
            });
            x.Position("topEnd", end =>
            {
                end.Search(s => s.Placeholder("Type here for search..."));
            });
            x.Set("bottomStart", "info");
            x.Set("bottomEnd", "paging");
        })                         

Output:

image

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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

https://datatables.net/reference/option/buttons.buttons

{
public bool Return { get; set; }
public string Placeholder { get; set; } = default;
public bool Boundary { get; set; } = false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants