I've gotten a WebApi to work as the backend for Tabulator. The backend is C# with a repository pattern, using Dapper. I've got the progressive loading working, but I'm kind of unsure how to fully get the page count to work. I have some ideas, but I'm not sure if they would actually be the best way to implement things.
Basically, here is what Tabulator is expecting back:
{
"last_page":15, //the total number of available pages (this value must be greater than 0)
"data":[ // an array of row data objects
{id:1, name:"bob", age:"23"}, //example row data object
]
}
Getting the "data" part of this back was relatively easy. Right now, I just hard coded a value in for "last_page". Using progressive loading, that "last_page" isn't really used, but I should know how to do this if I want to add real pagination to the table.
It would be much appreciated if someone could point me in the right direction for getting that "last_page" value and returning it together with the "data" object.
One thing I have thought about is a separate url that returns just the page count, and then sending this back from the front end when getting the data. This seems like it would work but doesn't exactly seem like the optimal way to go.
Right now, this is my controller, and you can see I just manually created a page count:
Is it good practice to get this page count on every single call to the backend? That's kind of why I was thinking about doing this in two calls. That way I could kind of be selective about when I made it do the math for the page count.
On the other hand, if new data was going in a table and it wasn't being recalculated every time...
Thanks,
Jay
Basically, here is what Tabulator is expecting back:
{
"last_page":15, //the total number of available pages (this value must be greater than 0)
"data":[ // an array of row data objects
{id:1, name:"bob", age:"23"}, //example row data object
]
}
Getting the "data" part of this back was relatively easy. Right now, I just hard coded a value in for "last_page". Using progressive loading, that "last_page" isn't really used, but I should know how to do this if I want to add real pagination to the table.
It would be much appreciated if someone could point me in the right direction for getting that "last_page" value and returning it together with the "data" object.
One thing I have thought about is a separate url that returns just the page count, and then sending this back from the front end when getting the data. This seems like it would work but doesn't exactly seem like the optimal way to go.
Right now, this is my controller, and you can see I just manually created a page count:
C#:
[HttpGet]
public async Task<IActionResult> GetCompanies([FromQuery]int page, int size)
{
Pager pager = new Pager(page,size);
string strUrl = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request);
string strUrl0 = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedUrl(Request);
try
{
var companies = await _companyRepo.GetCompanies(pager);
var result = new
{
last_page = "1000",
data = companies
};
return Ok(result);
// return Ok(companies);
}
catch (Exception ex)
{
//log error
return StatusCode(500, ex.Message);
}
}
Is it good practice to get this page count on every single call to the backend? That's kind of why I was thinking about doing this in two calls. That way I could kind of be selective about when I made it do the math for the page count.
On the other hand, if new data was going in a table and it wasn't being recalculated every time...
Thanks,
Jay