Donate

Cannot read property 'DateSorter' of undefined in Bootstrap Table

Good evening gents!
Doing some refactoring to one of my projects using the JavaScript prototype pattern, I encountered issues while calling the functions in prototype through the Bootstrap Table by Wenzhixin specifically in the data-sorter property. In document ready, I created an object of an EmployeeModel class that contains the function.
$(document).ready(function () {
       EmployeeObj = new EmployeeModel();
});
And in the data-sorter property, I called the custom function to sort dates.
<th data-field="signout_time" data-sortable="true" data-searchable="true" data-sorter="EmployeeObj.DateSorter">
 @Html.DisplayNameFor(model => model.EmployeeList[0].SignOutTime)
</th>
Doing so, throws an exception "Cannot read property 'DateSorter' of undefined". After further investigation, the table has set values for data-sort-name and data-sort-order properties.
<table id="" data-sort-name="signout_time" data-sort-order="desc" 
Removing these properties, finally fixed the issue.

Edit: This also occurs after a Post event or a form submission in ASP.NET MVC and bootstrap-table.js cannot read the DateSorter function. Given that the DateSorter function is called in an external JavaScript file. The solution to this is to re-arrange the calling of script files wherein the external file should be called first before the bootstrap-table.js.
<script src="~/Scripts/EmployeeScripts.js"></script>
<script type="text/javascript">

 $(document).ready(function () {
  EmployeeCommonObj = new EmployeeCommon();  
 });
 
</script>
<script src="~/Scripts/bootstrap-table.js"></script>
<script src="~/Scripts/bootstrap-table-en-US.js"></script>
<script src="~/Scripts/bootstrap-table-toolbar.js"></script>

Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.