How to display all items.. SHOW ALL in pagination?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
fabcreate
Posts: 2
Joined: 2015-06-13 03:54

How to display all items.. SHOW ALL in pagination?

Post by fabcreate » 2015-06-17 03:14

How to display all items.. SHOW ALL in pagination?

the show all at the top doesnt really displays all items. it just clears the filter, stil on pagination..

how can i-add an option to show all items and not paginated?

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 356
Joined: 2013-03-21 04:37

Re: How to display all items.. SHOW ALL in pagination?

Post by peebee » 2015-06-17 08:24

Currently it is not possible without custom editing of the generated files but it is something that would be very handy and has been requested on the Appgini wishlist in the past.

I am going to have a go at implementing this jquery plugin (not immediately but soon) to achieve the desired result and also to add a few other extras to the table: http://datatables.net

Here's the example for page length as you are after: http://www.datatables.net/examples/adva ... _menu.html

Having looked at the Appgini generated <table> html formatting and as jquery is loaded with every page, I think it should work OK without a great deal of time or effort involved. That's the hope anyway.

If I get it working, I'm happy to share the result and what's involved.

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 356
Joined: 2013-03-21 04:37

Re: How to display all items.. SHOW ALL in pagination?

Post by peebee » 2015-06-17 09:17

Wow!

I thought I might take a quick look at it before finishing work for the day. I spent literally 15 minutes and already have it working with extremely minimal editing to 2 x files only (header.php = include javascript and datalist.php = add an #id to the <table>). That's it - so simple!

A little bit of css styling required and it should be ready to go! I'll get back to you with a "how to" soon.

Perhaps Ahmad (the developer) might be interested implementing this (or something similar) into future versions?

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: How to display all items.. SHOW ALL in pagination?

Post by shasta59 » 2015-06-17 19:45

It is easier than that.

I am using 5.31

Look for, in the tablename_view.php file, the following:

$x->RecordsPerPage = 10;

Change the RecordsPerPage to whatever number you want. If you look in the bottom left corner, below the last record in the table view, it shows how many records there are.

Or, you can make it even easier. (Sort of).
At the top of the page you can write code which puts in a box into which you enter the number of records you wish to see then press a button to accept it and have the code attached to that button rewrite the value for RecordsPerPage. Then it will redisplay the page.

I did this for a client and our agreement (contract) prevents me from sharing that code. I am working on a different solution not using the same code structure. This way it is integrated into the page. It will also show how many

My new code, when I get time to finish it will have a buttons which says Show All on one page or something similar.

And here is another way:

Write code to set the value of RecordsPerPage before the page is displayed by having it lookup the # of records in your table and change the value of RecordsPerPage before displaying. The code lines would be only a few.

So many ways to do this within AppGini without a lot of effort. Saves adding in plugins etc. Then it is styled the way the current data is styled.

(Sorry for no code yet to do this but it will come in time but may take a fair bit of time)

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 356
Joined: 2013-03-21 04:37

Re: How to display all items.. SHOW ALL in pagination?

Post by peebee » 2015-06-17 23:25

Have to beg to differ there sorry Alan. This plugin couldn't actually be simpler. And it works a treat with no fiddling around or any additional coding required. All coding is done for you, including Ajax functions.

Moreover, it also gives you the possibility to display any number variation of lines that you would like your Users to be able to present.

Here's the end result after quite literally 10-15 mins work and this is with no additional styling or coding added to the default plugin code. A nice neat little dropdown with selectable varying table lengths that load instantly without page refresh.
screenshot1.jpg
DataTables jQuery plugin
screenshot1.jpg (71.48 KiB) Viewed 28722 times
This is the javascript required to be added for that result above:

Code: Select all

$(document).ready(function() {
    $('#tableName').dataTable( {
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
    } );
} );
$x->RecordsPerPage = 10; will only allow a set number of records to be displayed. That's not the purpose of this exercise.

The other consideration to "Show All on one page" is that I often work with tables containing 20,000+ rows. Show All is not really a viable option with that amount of records. In those cases, I will likely limit results to ""lengthMenu": [[10, 25, 50, 100, 200], [10, 25, 50, 100, 200]] with a max of 200 lines.

I've only just started work for the day but I intend to have another look at this later today sometime. Once I've had a play around, I'll try to post a "how to" then.

PS: I forgot to add that it is also Bootstrap compatible: http://www.datatables.net/manual/styling/bootstrap

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 356
Joined: 2013-03-21 04:37

Re: How to display all items.. SHOW ALL in pagination?

Post by peebee » 2015-06-18 05:46

I now have the DataTable plugin working OK to display "Show # entries" dropdown with very minimal effort or coding required. The following applies to Appgini V5.40+ which now includes header-extras.php in the hooks file (see notes below).

To achieve this result below, 2 x files require very minor editing:
screenshot2.jpg
screenshot2.jpg (85.73 KiB) Viewed 28715 times
1. In datalist.php, find this piece of code and add an id to your table (in this case I added: id="projectname")

Code: Select all

// begin table and display table title
		if(!$this->HideTableView && !($dvprint_x && $this->AllowSelection && $SelectedID) && !$PrintDV && !$Embedded){
			$this->HTML .= '<div class="table-responsive"><table class="table table-striped table-bordered table-hover" id="projectname">';
2. In header-extras.php in the hooks folder, add this:

Code: Select all

<!--  Include DataTables -->
        <style type="text/css">
		.dataTables_wrapper .dataTables_length {
  		float: left;
}		
		.dataTables_wrapper .dataTables_info {
  		clear: none;
  		float: left;
  		padding-top: 0.15em;
 		padding-left: 10px;
}
		</style>
		<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
		<script type="text/javascript" class="init">
			jQuery(document).ready(function() {						
			jQuery('#projectname').dataTable( {
				"sDom": '<"top"li><"bottom"><"clear">',
				"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]				
			} );
		} );
		</script>
That's it and you should have exactly as per the screenshot on all of your table views. You may need to play around with some CSS depending on the theme you are using.

NOTES:
1. The code above loads the Datatables jQuery plugin via cdn (see the src= url). You could also install the plugin locally and call it that way. See here: http://datatables.net/manual/installation
2. I didn't load the plugin's own CSS because it overrode my existing theme's stylesheet. I applied a small snippet of styling to the header-extras.php to align the dropdown and info line. You might have to play around with that.
3. If you are not using Appgini 5.40 or 5.41, you could add the header-extras.php code directly to the header.php
4. You can change the dropdown "Show entries" values with this line of code: "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]] - see here for more: http://www.datatables.net/examples/adva ... _menu.html
5. By default, the plugin loads search, filtering and pagination functions. I removed them with the "sDom" code in the javascript as Appgini already includes those functions.
6. Of special note: You will likely need to change $x->RecordsPerPage = 10; in tablename_view.php as mentioned by Alan as otherwise the Appgini "Records 1 to XX of XXX" at the bottom left of the table can be confusing with corresponding "Showing 1 to 25 of 50 entries". As it is, this plugin will only show the entries on a per page basis as defined in your Appgini project so if $x->RecordsPerPage = 10; - "Show All" will only show 10 records, not actually ALL records. This is the only downside I can see at the moment and I'm trying to work out a way around it other than something like $x->RecordsPerPage = 20000;?

Once called, this plugin allows you to add heaps of functionality to your table. See here for examples: http://www.datatables.net/examples/index

Hopefully that's useful to somebody. I like the plugin anyway :roll:

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: How to display all items.. SHOW ALL in pagination?

Post by shasta59 » 2015-06-18 16:52

Well I will have to go and look at it and see how it works. Always looking for something easier and faster.

Always worth looking at different ways to do things. Thanks for the good write up on it.

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: How to display all items.. SHOW ALL in pagination?

Post by shasta59 » 2015-06-19 19:07

Peebee

I am looking at the issue with the show all limit being based upon the number in RecordsPerPage and am trying a few things to get around that. Thought I had it working but it is messing up around 2% of the time and I have not figured out why yet. When I get it resolved I will get in touch. I am still using 5.31 but the solution should be the same.

What I have done is have code which, when All is selected it modifies the value in RecordsPerPage dynamically. Since I have this as a setting in my own admin page area of settings I am just calling the same code to do that change. Am setting it aside for now as I have a client deadline I should be working on. (Grin) (Darn got sidetracked again! - LOL)

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

Post Reply