Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Yii2 By Example

You're reading from   Yii2 By Example Develop complete web applications from scratch through practical examples and tips for beginners and more advanced users

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785287411
Length 344 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Fabrizio Caldarelli Fabrizio Caldarelli
Author Profile Icon Fabrizio Caldarelli
Fabrizio Caldarelli
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Starting with Yii2 FREE CHAPTER 2. Creating a Simple News Reader 3. Making Pretty URLs 4. Creating a Room through Forms 5. Developing a Reservation System 6. Using a Grid for Data and Relations 7. Working on the User Interface 8. Log in to the App 9. Frontend to Display Rooms to Everyone 10. Localize the App 11. Creating an API for Use in a Mobile App 12. Create a Console Application to Automate the Periodic Task 13. Final Refactoring Index

A summarized footer row in a grid


One feature of GridView is that it shows summarized or statistical data, usually as a footer row or first row, to get the data immediately (instead of scrolling down the page to the bottom of the grid).

A column of the GridView widget has an attribute named footer to identify the last row of the current pagination. A value filled in this attribute will be placed in the last row of the grid.

By default, showing the footer is disabled; to enable the footer, it is enough to set the attribute showFooter of GridView to true. Then, we need to insert data in the 'footer' attribute of the column that we want to show.

For example, we want to display the average price per day of rooms.

Add this code at the top of the grid view in basic/views/reservations/grid.php to calculate the average of price per day:

<?php
use yii\grid\GridView;
use yii\helpers\Html;
?>

<h2>Reservations</h2>

<?php 
$sumOfPricesPerDay = 0;
$averagePricePerDay = 0;

if(count...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image