When it comes to creating CRUD tables in school, I've always used scaffolding per page. However, I recently wanted to experiment with performing all operations without using Partial View. I decided to implement AJAX by following a tutorial on
Everything was working smoothly until I wanted to incorporate the DataTable API for adding search and sorting features to the table. The current state of my table can be viewed HERE.
It seems like there's an issue with recognizing the data being passed from the JavaScript code that I wrote, especially evident in the "Showing 0 to 0 of 0 entries" message. Is there a way to properly load data from AJAX into the DataTable script? Any assistance would be greatly appreciated! Below, you'll find a snippet of my code.
UPDATE: I moved the DataTable initialization to Inventory.js and now the DataTable occasionally works upon page load. It's quite random when trying to refresh the page multiple times. Even adding a delay before the page loads doesn't seem to have any effect. Does anyone have insights into what might be causing this?
Inventory model:
public List<Inventory> ListAll()
{
// Code for retrieving inventory list
}
InventoryController.cs:
public JsonResult List()
{
return Json(invDB.ListAll(), JsonRequestBehavior.AllowGet);
}
Inventory.js (Data retrieval):
function loadData() {
// Code for loading data via AJAX
}
Index (DataTable script):
@section scripts {
// DataTable initialization script
}