Data Range - Server-Side Processing (Laravel)
Data Range - Server-Side Processing (Laravel)
Vanvin
Posts: 2Questions: 1Answers: 0
I have added my code to the jsfiddle link below. I need to find a way to add a date range filter to server-side processing. I have a date that is stored in a database. I cannot find any documentation or examples that aim to do what I am doing. Any help on this matter would greatly appreciated.
This discussion has been closed.
Answers
You started out okay, you have a min and max input element. You pass them in your ajax "data" so they are now appearing in your request variables (either the URL for GET or parameters for POST). Your ajax page now must be able to read the request variables along with the other passed variables like start and length from dataTables ajax request. Then it would seem you just need to craft you URL. Select * From myTable where datestart>(request var datemin formatted properly) and datestart<(request var dateemax formatted properly).
Glenderson - thank you. I have updated my code. The part I am getting stuck on is the function that generates the query to send back to the datatables (basically the where between part). -- Do you know how to do this or can you recommend any documentation?
The function is included in the JS fiddle below:
if ($request->has('min_date') && $request->('max_date'))
{
$instance->collection = $instance->collection->filter(function ($row) use ($request)
{
return *Not sure what goes here
});
Link: https://jsfiddle.net/9ymy1h1b/1/
When using server side processing, typically it's the ajax page that you write that does all the work. You write a json formatted response that dataTables then puts into the cache memory.
I work in the vb.net world, so don't use the built in scripts of php in datatables.
Your ajax page should
1 - Read the request variables
2 - Craft the sql query
3 - make the database connection
4 - send a json formatted page (not html) to dataTables.
So, your return would be
{"data":[{... record#1 ...}, {... record#2 ...}, {... record#3 ...} ...]}