Grid Extension Page & Script rendering #7042
Replies: 1 comment 3 replies
-
Hello, the ModulePage.cshtml is used to avoid code duplication. To manage the scripts that run before and after the page loads, you can use MyModulePage.ts directly. The pages have only one div element that the script needs to populate. You can set the execution order in the export default function pageInit() {
// Execute code here before user grid created.
initFullHeightGridPage(new UserGrid($('#GridDiv')).element);
// Execute code here after user grid created.
} |
Beta Was this translation helpful? Give feedback.
-
Hey Guys!
I am struggling with rendering the script in Serenity. I looked at _layout.cshtml and I see that the
PageInitScript
section is placed before the render body - which makes sense because later on other scripts fromRenderBody
are inserted so we keep the script execution in order, but overall it is advised to always have a script at the very end of the page. Also, this is the case when we havehideNav = true
, so when we have ESM scripts we do not even try to fire PageInitScript section - anyway I feel that someone in the past had a great idea of managing scripts but this was kind of lost in the way.Anyway, I want to do it on my own so this is no problem to modify my layout. The problem is with the view in the Serenity.Extension area:
~/Areas/Serenity.Extensions/ModulePage/ModulePage.cshtml
ofc I can do it on my own and copy & paste the code from Serenity.Extension to my solution and modify it there, but that is not ideal - right?Can I suggest you guys to have this.GridPage method more configurable for this case?
Also please consider the idea of rendering the script at the bottom.
let's have a
@await RenderSectionAsync("PageInitScript", false);
in the_layout.cshtml
always at the bottominstead
<script type="text/javascript"> $(function () { @RenderSection("PageInitScript", false) }); </script>
have a
@await RenderSectionAsync("PageInitScript", false)
let's modify
\common-features\src\Serenity.Extensions\Areas\Serenity.Extensions\ModulePage\ModulePage.cshtml
with instead:<script type="module"> import * as imports from '@Html.ResolveWithHash(Model.Module)'; imports.default && imports.default(@(Model.Options == null ? "" : Html.Raw(JSON.Stringify(Model.Options)))); </script>
to have:
@section PageInitScript { <script type="module"> import * as imports from '@Html.ResolveWithHash(Model.Module)'; imports.default && imports.default(@(Model.Options == null ? "" : Html.Raw(JSON.Stringify(Model.Options)))); </script> }
I hope this makes much more sense than what it is right now. With this, it will give me much more control over how I want to get all scripts rendered on the layout.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions