How to add the summary in the Gridview footer in Yii2

category:  Yii2.0 framework

Currently, I am building the invoice feature in my own application with Yii2. I use the gridview widget for displaying all invoices data. I want to add the grand total for all invoices. Just like the screenshot below. To do that, I have to add the extra code in two places. Note that, I generate the CRUD from Gii. So I will show only the code that I add for displaying the grand total at the gridview footer. First place, … Read More

Multiple grids on one page in Yii2

category:  Yii2.0 framework

Recently I upgrade my application and I add two Gridview widgets on one page. Everything seems working fine until I notice the pagination of all Gridview widgets won’t work properly. There are two issues that I found.   Issue #1 One issue is every time I click on one of pagination of any Gridview widget, all paginations changed. For example, I click on page number 5 of one of the paginations and other paginations change to 5 as well. To fix … Read More

Global search box in grid view widget in Yii2

category:  Yii2.0 framework

One feature that the users like, is the global search. With CRUD from gii module, the index.php comes with filters for each column in grid view. The attribute calls filterModel. It is good and it is working perfectly. But it would be better if users can search for anything from one search box. In this post, we will implement the global search box for Currency index page. What we will do CurrencySearch.php (in models folder) Add new $globalSearch variable Set … Read More

Ajax validation in Yii2

category:  Yii2.0 framework

Yii version 2.0.13.1  When you are working on a form validation, sometimes it is better for the users if you do the Ajax validation on a form. This way, users will get the warning message after they fill in each field. Here is an example. We have a branch table. We want a branch name to be unique. What we will do: Model – In a branch model, we set the branch name in a unique rule. View – In … Read More

Override delete confirm dialog in Yii2

category:  Yii2.0 framework

Yii version 2.0.13.1 In the grid view widget, the delete button uses the window confirm dialog which is simple. But it would be better if it can be changed to use the confirm dialog with bootstrap style. Since Yii2 is already integrated with the bootstrap widget. In this tutorial, I will share how I implement the new confirm dialog with a translated message by Yii::t().   Here what we will do Download the bootboxjs which is a small javascript library. It allows you … Read More

Language switcher in Yii2

category:  Yii2.0 framework

Yii version 2.0.13.1 Currently, I am building the custom application with Yii2. I want to add the language switcher in the application. I found some posts that help but these posts won’t explain well. So I try to explain what I did here. Here what we will do: create the static value in config/params.php create a language dropdown list in layout/main.php create a actionLanguage() in the controller create a LanguageSelector component create a JS file for calling the actionLanguage() via … Read More

All javascript won’t work after Pjax reloads in Yii2

category:  Yii2.0 framework

Yii version 2.0.13.1 When you work with Pjax either Pjax jquery or Pjax module, you may face the same issue as me. I am working on the Pjax widget in Yii2.0. The widget uses Pjax jquery. ProblemEvery time the Pjax reloads, all js that attached to DOM in Pjax container won’t work. CauseAfter Pjax finishes reloading, the js that set to DOM in Pjax container will not pick up on these changes. SolutionYou must reinitialize the js to DOM after … Read More

Pjax is not working, reloads the whole page

category:  Yii2.0 framework

Yii version 2.0.13.1 Recently I am working on building the custom application with Yii2.0. I have one issue with Pjax widget. It turns out to be a common issue when you are working on Pjax. ProblemI want to render the creating form in the modal on an index page. After users submit the form, the modal will be closed and the grid view will be refreshed. This way, users won’t leave the index page. The problem is Pjax reloads the whole page … Read More

1 2