Hi,
I load page-specific javascript files as follows.
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await js.InvokeAsync("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 (
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; 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