ekondur / DatatableJS

Jquery datatable with entity framework using MVC html helper
MIT License
36 stars 15 forks source link

adding dom option as per https://datatables.net/reference/option/dom … #122

Closed Alexplose closed 1 year ago

Alexplose commented 1 year ago

…and allow separated rendering of html & script

it can be used like this :

` @{

                var datatable =
                Html.JS().Datatable<DashboardItemViewModel>()
                .Name("DashboardGrid")
                .Columns(col =>
                {
                    col.Field(a => a.ID).Visible(false);
                    col.Field(a => a.Name);
                   ....
                    col.Command(a => a.ID, "", "", "onClick", text: "Click").Title("");
                })
                .Data("getPeriod")
                .Searching(true)
                .Callbacks(x => x.InitComplete("initComplete"))
                .Language("https://cdn.datatables.net/plug-ins/1.13.4/i18n/fr-FR.json")
                .URL(Url.Action("GetDashboardData", "Dashboard", new { area = "V2" }), "POST", camelCase: true)
                .Dom("t")
                .ServerSide(true);
            }
                @(datatable.RenderHtml())

`

then :

@section Scripts { @(datatable.RenderScript()) }

ekondur commented 1 year ago

Hi @Alexplose, thank you for your great contributions. What is the main reason or benefit for separating render parts? Is it not possible to add the "Dom" feature without separating these?

Alexplose commented 1 year ago

In a layout file in asp.net core, the scripts tags comes after the RenderBody, then the scripts section is rendered after.

As I'm referencing jquery, datatable and all my js libs after the RenderBody, the way your TagHelper works leads to a JS error as datatable is not yet defined.

So all scripts stuffs must be referenced in the script section to be rendered at the right time when all libs have been loaded.

See this link : https://learn.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-7.0

Is this clearer?

ekondur commented 1 year ago

Hi @Alexplose I can use it in my main project with script priority editing, but it's good that it still has separate options. Thank you. I will be creating and testing tickets for this and dom-related improvements and publishing them as soon as possible.

ekondur commented 1 year ago

Hi @Alexplose it is published with 3.7.0 version, By the way, did you miss the _dom property here, because it is possible to set?

Alexplose commented 1 year ago

Hi @Alexplose it is published with 3.7.0 version, By the way, did you miss the _dom property here, because it is possible to set?

I don't understand, where?