Here’s a code that retrieves data from database and makes everything ready to pass to Tabulator data table.
C# Mehod
[Authorize]
[HttpPost]
public IActionResult GetData(int page, int size)
{
// Assuming _context.Courses is a DbSet in your DbContext
var totalRecords = _context.Courses.Count();
// Calculate the total number of pages based on the page size
var totalPages = (int)Math.Ceiling((double)totalRecords / size);
// Retrieve the data for the requested page
var courses = _context.Courses
.OrderBy(c => c.Id) // Adjust the sorting as needed
.Skip((page - 1) * size)
.Take(size)
.ToList();
// Create the response object with the required properties
var response = new
{
last_page = totalPages,
data = courses
};
// Return the data as JSON
return Json(response);
}
Javascript Code
Here’s the code by which you can initialize Tabulator data table.
CSS Styles
And here are the styles needed for Tabulator context menu (right click):
Have a great day!