I have used ng-table for my table which works well for pagination, sorting. and I have used ng-model for filtering table data (in short search).
My problem is when I do search it is searching but suppose the word I am searching is at page 3 so it not shows anything till I do not do show all records (till I do not remove pagination). I want to remove pagination automatically while search or anything so that the record will come on first page.
Help me, Thanks in advance.
I think you are currently using pagination in client side data.the better approach is to use the searching in server side return result using limit and offset.
Related
I need to search details. I have written the code for searching ie, the textbox and search button is written in the homepage as well as the "search_result.php".
Pagination without searching is working well. the searching also is working without pagination.
So I guess if the search value from the homepage is stored in the session then may be I'll get that with pagination.
If there is something more. please help me.. :(
You haven't share code so am in dark what your actually doing or whats wrong.
But there is alternative.
I guess you should try: https://datatables.net/
You does not have to worry about the search results and pagination. datatables takes care of it.
Although datatable in this example fetch all records at once, that may affect on performance if your working with large no of records,
in that case go for : https://datatables.net/examples/data_sources/ajax.html
Let me know if it works for you.
I have a website were the user types in a city (f.e.: Washington), presses search and via ajax json it gets the entries from my database. I never know how many entries it got, so let's say this time I have 40 entries in my database where it says "Washington". Now a function appends all 40 entries on the site.
How do I get it to show only 4 entries and then add number buttons where the user can go to page "X" to see another 4 entries and so on?
second question:
And how do I tell the script to just add a specific amount of number buttons ( In this case just 10, since 10*4=40 already )?
I don't necessarily need a full code example, just a good explanation on how I can do this (without a plugin).
Here a simple drawing to clarify this:
Thank you very much in advance for any answer.
There is an excellent tutorial on tutsplus covering the kind of pagination as seen on your image. You would just need to modify the sql query in the script to match your requirements, point your ajax url to this pagination script, and ensure the results are returned as json. Hope this helps!
To setup the pagination you would need to use mysql LIMIT & OFFSET, also counting the total number of results and returning that in the JSON to set the correct number of pages in the pagination.
You would also need to pass the page number in the ajax call through a GET parameter so you can set the OFFSET correctly and return the correct page.
I tried some jQuery pagination plugins but they were a little buggy. So I chose pure PHP and made a really simple one myself, since the tutorials seemed a bit too overloaded to me.
I just pass pagenr via GET and in my script a set a specific amour of results to be displayed via Limit $start(=0 if pagenr=1), 10
If the pagenr is bigger then "1" it undergoes a for loop which adds up "10" to "$start" every time.
And with these values and COUNT(*) I do the pagination with for and if loops.
Does anyone know of a link to a site that has a tutorial/code on good way to paginate information coming from a database? (without page refresh) I have spent the better part of the day looking for a site that has what I need. Most are dealing with static/fixed data in the forms of lists etc.
I need one that has something like this for my tables:
Data Data Data Data
Data Data Data Data
Records 1 to 8 of 27 First Previous Next Last
We just implemented a few things using this plugin for JQuery:
Datatables.net
It works on basic html tables and has support for AJAX. Basically you would just write a PHP page that returns a partial result from your database in JSON, etc. The plugin will handle making the AJAX call and displaying the data.
This is only a very partial answer (sorry, not much time atm) but look for the 'LIMIT' command in mysql. It lets you pull back only a certain set of records, say records 11-20. I use that when I do pagination.
Again, this isn't complete, but hopefully it'll help!
I've worked with this one quite a bit. jQgrid... seems to be pretty well maintained.
http://www.trirand.com/blog/
I have a php code that fetches data from mysql. The data has (say) 15 rows. I want to display only 5 rows at a time to the user, with links to each of the set (3 in this case) such that when a user clicks on either of the links, the same page will show the corresponding results. Since, php code has the final result set, I don't want a solution that involves me to navigate to other pages and possibly re-calculate the next set of solutions (5~10 or 10~15). How can I do this? Thanks in advance.
If I am using javascript or ajax, how can I achieve this? I don't know javascript much.
You can try loading everything in your page and simulating the pagination thanks to javascript.
An example in jQuery here
It sounds like you want to send the Data as a complete set to the client but not let him display everything to the user. So use Javascript to just show you the pages 1*page_number to 5*page_number (with a for-loop).
By far, the easiest solution in this situation is a Dom-based Grid system. I recommend checking out Datatables. In essence, the Datatables code will take a fully-formatted html table and reformat it to include only the amount of rows you tell it to, with paging on the bottom as you've requested. In addition, you can turn on such features as filtering, toggle-able length, sorting, and selection. Once you get the hang of it, the additional code takes no more than a minute per table and the features are outstanding.
This is really straightforward. Use PHP to output ALL of the table, with all the rows. The only gotcha here is to include the full html, including <thead> and <tbody> Give the table an id such as "example"
Now, include the files that you download from the datatables site--datatables.js and Jquery.js. Instantiate the jquery like this:
$(document).ready(function() {
$('#example').dataTable();
} );
That's it. As you can see from the examples, it's a really cool tool. Good luck.
I am just learning php and ended up at this tutorial http://www.w3schools.com/php/php_ajax_livesearch.asp
Till now my PHP search file looks the same as in example but i changed the if (strlen($q) > 0) to if (strlen($q) > 3) to display results after typing minimum 3 words. I am wondering how can i make the results paginate if there are lots of them?
Thanks
Roshan
You would need to page after obtaining the number of records from your database.
Paging should be done by the same script that echos your ajax response.
Here is how to page:
PHP MySQL paging.
The idea of search suggestions is to show the user what do you have in your site, in terms of relevance, that match his query. This being said, you should only throw a subset of results, being the first result the most relevant, instead of the whole file or database. In others words, you don't need pagination.
Show the user 5 or 10 items, if he doesn't find what he's after he'll keep writing until he finds it. If he doesn't finds it he will just search it. Remember that it is a suggestion and nothing more.