Take a glance again at the screenshot about what effect we will create.
We've finished rendering work of the new custom
8 Register Widget Assets
8.1 Register JS In DemoPagerAsset
8.2 Register DemoPagerAsset In DemoPager Widget
DemoPagerAsset, we still need register
DemoPagerAsset itself to
DemoPager widget. We do this step in
run method of
After registering, Yii2 will echo
script tags automatically before HTML end
Yii Pager Examples
Yii Pager Cgridview
- when user select a new page size, we'll replace page size parameter in query strings of current URL with new selected size and then refresh browser;
- when user input a new target page number and press enter key, we'll replace page parameter in query strings of current URL with new page number, then jump to the new URL;
Next, we need call above
init function and pass
registerJs method of
yiiwebView to do the magic.
To allow flexible page size, you should not hard coded the page size in your controller.
ListView in your view file.
Check the result by accessing URL:
http://YOUR_HOST_OR_APP/index.php?r=test/test. Software free download games.
You may discover that our
DemoPager is ugly now because there's no CSS style yet.
There are two ways to style
- Write CSS styles in
YOUR_APP/widgets/demopager/assets/css/demopager.css, and package this CSS file together with
DemoPagerwidget class. But this way lose flexibility if widget user want to add dynamic styles;
- Pass CSS class name or CSS styles directly as HTML options while using
I'll demonstrate the second method here.
That's all, now our
DemoPager looks really good. Source codes are available.