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.
Related
Is there a way to convert a pagination to a collection/array to get all items like:
Users::where(...)->paginate(15); //paginated
Output: 15 per page
Users::where(..)->get(); //not paginated
Output: all Users per page
So i is it possible to do something like that:
Users::where(...)->paginate(15)->removePagination();
Wanted output: all Users per page
You have 2 choices:
either retrieve the complete query result by chaining ->get()onto your query.
call ->paginate() to retrieve a pagination instance, which automatically retrieves the first page, and it automatically links the example.com?page=1 url param.
(there are also some other functions that complete the query like ->pluck() or ->value() which might not be applicable to you)
As far as I'm aware you cannot revert to the complete collection instance when you have the pagination retrieved (\Illuminate\Contracts\Pagination\LengthAwarePaginator), nor does it make sense to do so since the idea is to retrieve as little data as possible such that your application stays fast.
Maybe you should explain what you're trying to do; for instance you can retrieve the total count in the paginator using SomeModel::query()->paginate()->total(), among other things. You might not need the complete query after all.
I have a page with table of some data (let's say posts). I have a form there which leads to the same page but with get parameters. So when I choose December in dropdown list form will lead to posts/index?month=december. Controller index method makes eloquent query using query string parameters to filter rows. After that I click edit post(or add new post) and change something through edit form. Then update or store method redirects back to index as usually. What is the best way to come back to index?month=december page? Sessions? How should I do it? Set some values from query to session in Controller index method when I come there first time and get them also in Controller method from session after editing/creating?
Try to append all request parameters in the redirect:
return redirect()->route('route_name',['month' => request()->get('month')]);
You can read more about this in this section in the docs.
I have a service which is responsible for getting the data from a backend.
The data is shown via a component in its nginit method. It is shown in a table (html table).
I would like to be able to manipulate data without having to reload it each time in my table : ex : delete a row, add a row ... I want all of this very fluid. The data is coming from a database.
So my question is :
Should my service return an observable or an array ?
Is nginit the best place to show my table ?
How should I do things maybe to manage everything in memory? I do not know.
Thanks for any advice.
I would save the data into an array then use lodash to manipulate it.
You could edit, delete, and add rows using lodash's built in functions. When you want to save the data to the backend you would then post the array back to the server. This will keep backend requests to a minimum which will help your performance.
For example you could delete elements from the array using the remove function, https://lodash.com/docs/4.17.4#remove
Lodash can be setup like this https://medium.com/#gtsopour/importing-lodash-into-angular-2-typescript-application-94590365f46d#.9mdcdjnac
Of course you could do this all using raw js though but I find Lodash very rich and easy to use.
I'm trying to implement a dashboard similar to facebook in cakephp (getting posts and post them to timeline and while you press see more it keeps retrieving posts from previous offsets) , but im still confused about the logic and tools , should i use the cakephp pagination class in my implementations.
$this->paginate();
it somehow should be called through ajax accourding to some performance wise
Any helps or suggestions where to start from ?
Thanks All
Don't use paginate
If you paginate something that you are prepending data to - you're going to get data overlapping such that you ask for page 2 - and get the end of, as far as the current user is concerned, the previous page.
Use a timestamp
The normal technique for an endless stream of data is to use a query like:
SELECT *
FROM foos
WHERE created >= $previousLastTimestamp
ORDER BY created DESC
LIMIT 20
Note that while I'm using created in this example - it can be any field that is pseudo unique.
When you first render the page, store the timestamp of the last entry in a javascript variable, then your "get more posts" logic should be:
Make an ajax (get) request, passing the last timestamp
Perform the above sql query (as a $this->Foo->find call)
in your js update the last timestamp so that you know where you are up to for the next time the user clicks "get more posts"
The reason to use a >= condition is that, unless the field you are testing against has unique values, it's possible for there to be multiple rows with the value you're testing for. If you have a naturally-unique field that you are sorting by (id) then you don't need to use greater-or-equal, you can simply use greater-than, and avoid needing to think about duplicate rows.
Here's a reference which explains in more detail why you should handle systems like this avoiding traditional pagination.
As you maybe aware from the following post I'm new to the Zend framework and web programming so any help is greatly appreciated.
What I want to do is have a page that my users can search for clients stored on the database have the results returned via a table. I know how to do this in a traditional form -> post -> results page manner but I would like to implement the following:
Have two or more Dojo autocomplete combo boxes that the user can enter search criteria into (I've found examples of this on the web and should be ok implementing this.)
Use the text entered into the query the clients table in the DB.
Return the results in a table on the same page without having to redirect, and if possible have the table update the results as the user types into the combo boxes.
for example if the user types "Fa" for example the table will have
"Farrell
"Fagan"
"Farrelly"
As the user continues to type eg "Far" the table will have
"Farrell"
"Farrelly"
As you may have already guessed I need help with parts two and three. I've tried searching using keywords refresh and autocomplete but I've been unable to find anything that comes close to what I need.
Can anyone please provide links to tutorials/examples of how to do this in the Zend Framework. I know code is a lot to ask for but if anyone is feeling generous go ahead.
Just in case it makes a difference I'm using Doctrine ORM to handle my models.
Thanks in advance for any replies.
Graham
The basic gist is this...
Using the AjaxContext helper, add an html context to your action.
Move your table markup into a .ajax.phtml file and replace it in your normal view with a render call
Example
<?php echo $this->render('controller-name/action-name.ajax.phtml') ?>
Add your JavaScript event handlers to the page. When requesting the AJAX content, add a format=html parameter to the request. This will trigger the AjaxContext helper, returning only your table markup which you can then inject into the page.
The best part about this approach is that it degrades gracefully. If JavaScript is disabled or not available, the page reverts to the old school form -> post -> results method.
Have a look at my AJAX pagination post here for some pointers - http://blog.philipbrown.id.au/2011/03/awesome-pagination-with-zf-paginator-ajaxcontext-and-the-html5-history-api/
This uses a page parameter in the same way you want to use your search criteria so it should do as a base reference.