Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

I load page-specific javascript files as follows. But when I call the page it gives an error like this


Hi,


I load page-specific javascript files as follows.


<script suppress-error="BL9992" src="@KTTheme.GetAssetPath("zcustom/js/datatable.init.js")"></script>



protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await js.InvokeAsync<IJSObjectReference>("TestDataTablesAdd", "#kt_datatable_example"); //line 473
}
}


Javascript File:

function TestDataTablesAdd(tableName/*, jsonData, jsonColumns*/) {
$(document).ready(function () {
var table = document.querySelector(tableName);

$(table).DataTable({
//"data": jsonData,
//"columns": jsonColumns,
"fixedHeader": {
"header": true,
"headerOffset": 73
},
columnDefs: [
{ orderable: false, targets: 0 },
{ orderable: false, targets: 1 },
{ "visible": false, "targets": 1 }
],
order: [[2, "asc"]],
"scrollX": true,
//"responsive": true,
"info": false,
"pageLength": 10,

"select": true,
"select": {
style: "multi",
selector: "td:first-child input[type="checkbox"]",
className: "row-selected"
}
});
});
}
function TestDataTablesRemove(tableName) {
$(document).ready(function () {
var table = document.querySelector(tableName);

$(table).DataTable().destroy();
// Removes the datatable wrapper from the dom.
var elem = document.querySelector(table + "_wrapper");
elem.parentNode.removeChild(elem);
});
}


But when I call the page it gives an error like this

[2023-09-27T04:38:08.993Z] Error: Microsoft.JSInterop.JSException: Could not find 'TestDataTablesAdd' ('TestDataTablesAdd' was undefined).
Error: Could not find 'TestDataTablesAdd' ('TestDataTablesAdd' was undefined).
at http://localhost:5070/_framework/blazor.server.js:1:497
at Array.forEach (<anonymous>)
at s.findFunction (http://localhost:5070/_framework/blazor.server.js:1:465)
at E (http://localhost:5070/_framework/blazor.server.js:1:2611)
at http://localhost:5070/_framework/blazor.server.js:1:3499
at new Promise (<anonymous>)
at Ft.beginInvokeJSFromDotNet (http://localhost:5070/_framework/blazor.server.js:1:3480)
at Ft._invokeClientMethod (http://localhost:5070/_framework/blazor.server.js:1:75072)
at Ft._processIncomingData (http://localhost:5070/_framework/blazor.server.js:1:72696)
at Ft.connection.onreceive (http://localhost:5070/_framework/blazor.server.js:1:67009)
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at EruTipWeb.Pages.SystemPages.TestPage.OnAfterRenderAsync(Boolean firstRender) in T:\....\TestPage.razor:line 473
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi,

Thank you for reaching out to us.

You can try adding your functions to the window scope like this:


window.TestDataTablesAdd = TestDataTablesAdd;
window.TestDataTablesRemove = TestDataTablesRemove;


Additionally, ensure that your JavaScript file is correctly loaded on your page.

Regards,
Lauris Stepanovs,
Keenthemes Support Team



Hi,
It worked this way, thank you.



Hi,

Glad to hear that. All the best with your project!

Please don't hesitate to reach out if you need anything more from us.

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Your Support Matters!

We will highly appreciate your Metronic Review on Themeforest.
Please go to Themeforest Downloads page, select Metronic & leave your feedback.
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(