Where can I find information about Laravel pagination vs datatables pagination? - laravel

I have been working with some functional datatable examples, they work perfectly, they are able to handle any number of records and seems that they don't take care about pagination, or that's what I can see.
When I translate those examples, as they are, to my own code, laravel pagination seems to take control, so by default I cannot work with more than 15 records with datatable (great looking pagination controls), so I have to use php ->links() for being able to keep seeking for records, but now I have 2 set of pagination controls and they are not synchronized. The datatable controls are now a subset of laravel's (I can use protected $perPage at my model, but it only changes the number of records with laravel and datatable still has a separated pagination set of controls ). Are there some readings or articles about, I want that my datatable manages pagination as in the examples I'm working with. I've being looking for information but maybe is too obvious.
Thanks in advance.

Related

how make a laravel pagination component?

I have a slider component with a back and forward button and I want to get data in sort of pagination how can I do this?
I just want to do this without using Vue.js or livewire just laravel , JS and JQuery.
Laravel's Query Builder provides a paginate method that gives you a LengthAwarePaginator. Normally, you would render this in a blade view with $items->links(), but instead you can convert its result to JSON (https://laravel.com/docs/8.x/pagination#converting-results-to-json). That way you can use the results in JavaScript any way you'd like.
First, why using slider to create a pagination? there are better approach like lazy load, filter column, and simple pagination. lazy load is best for performance i guess.
If you insist to create a slider component, just wondering, how many data that you have? and how many data that you want to retrieve to screen? Imagine, you have more than 1.000.000 rows in your database, you sure wouldn't want to query for them all for real time updates to your screen. Why i tell you 'query them all'?
Let me tell you, if you do a pagination using laravel default pagination (using limit and offset), the flow behind this is like this:
DB will select all of your rows that you have
DB will limit your row depends on limit parameter
DB will scan row one-by-one to match the offset that you want
DB will retrieve the data that you want
With that flow, that's why pagination (limit & offset) is not good enough if you have a lot of data. The solution is change your pagination logic from limit & offset to query like this (case: auto incremental id):
SELECT
*
FROM
payments
WHERE
Id > 15
LIMIT 20
or for descending approach, you can query like this:
SELECT
*
FROM
payments
WHERE
Id < 50
ORDER BY Id DESC
LIMIT 20
Then in laravel, send a json that include a pagination data. So, in javascript you just have to align the pagination data with library or your own pagination logic.

JSF update changed values only

I´ve tried to get some informations about my idea, but still haven´t.
I wan´t to know, if there´s a way to achieve this:
I´m using a primefaces <p:dataTable> to display a list of items. For updating my table if some entries changed, I´m using datatableWidgetVar.filter() within the oncomplete event of <p:ajax>. Because the handled lists are pretty big (~50k-100k entries) it takes a few secs to 'update' the dataTable by its filter method and there is a 'flickering' I´d like to remove...
I don´t want the user to see, that components are reloaded, I mean it should be more 'smooth'. Is there a way to compare those 2 lists and only update the changed rows, so I don´t need to rerender 50,000 items? Or shall I pass the changed items (by id maybe?) to my jsf page and select the rows that are affected? Does primefaces offer such a algorithm?
Thanks in advance, let me know if you need some code or more details ;)
EDIT:
I´ve been thinking about that again and what about:
access the dataTable´s underlying list of items (client-side)
compare the server-side (newer) list with the (older) client-side one
get the changed (modified,added,removed) entries
force my dataTable to update only those 'rows'
Is this a good practise?

Avoid query each time the page is loaded

I work on an educational website in which we show dynamic filters. What does this mean? We now have several course categories that will increase in number in the following weeks.
Right now categories are a string field in each course. I'm planning to model this and create a Categories table. Having done this, it would be pretty easy to load the filters based on the categories we have on the database. However, I see the problem that each time the website is loaded, the query will be made.
I thought of caching these categories but I'm guessing is not the best solution.
Any idea on how can I avoid these queries each time but get this information from the database?

Yii CGridView pagination

I'm using CArrayDataProvider (which is basically a customized query i've created) that returns all the results (over 1000) from the database.
I'm using the results in the view but when i'm using the pagination it's going back to the controller for another query.
my question is: is there any way to move on the the next set of results (already part of the result array) without going to the controller and model again.
*My controller has a fairly advanced function which requires variables and parameters which i dont have in the view when trying to use standard AJAX request for the next page.
thanks,
Danny
my question is: is there any way to move on the the next set of
results (already part of the result array) without going to the
controller and model again
Then my answer would be NO if you was using CGridview's pagination. In your situation, you have to make the pagination by yourself instead. You have already selected all of records, and would like to manipulate them on your client side, you really don't need the pagination of CGridview at all.
Pushing all of records into a page on first load is not good idea, but maybe your requirement has asked, I just say that.

optimizing ajax based search

I am doing a ajax based search which suggests the values from the database tables as the user inputs fields in the search box. It does work but its really very slow, takes more than 10 seconds minimum for any suggestions to load. how do I optimize this to make it fast..
Like Index it/save it in cache/crawl?
Right now autoSearch() js function is fired which retrieves data from the related table to load the suggestions. how do I make this faster?
I dont know if this will make a difference but I am using grails/groovy for application development.
Thanks
Priyank
Have you added an index to any searched fields (or checked in the database to make sure the examined fields are indexed)?
The Grails GORM does not automatically create indices for text fields unless you add the appropriate static mapping to your domain class.

Resources