GithubHelp home page GithubHelp logo

yii-remember-gridview's Introduction

Yii Remember Gridview

Forked from pentium10/yii-remember-filters-gridview

The ZRememberGridViewBehavior Yii extension adds up some functionality to the default possibilites of CActiveRecord/Model implementation.

It will detect the search scenario and it will save the filters from the GridView. This comes handy when you need to remember them between navigation during page changes. For lot of navigation and heavy filtering, this functionality can be activated by just a couple of lines.

It supports default filter values and remember scenarios also. For example if you want to show only eg: Active Products, you can setup the default filter using this extension. Or if you have the same modal on different views, you can set different scenarios to remember state separated from each other. See the optional params under Advanced Functionalities and Scenarios section.

Please login to see the Demo image!

Requirements

  • Yii 1.1

Install

We recommend installing the extension with Composer. Add this to the require section of your composer.json:

"zmiftah/yii-remember-gridview" : "dev-master"

You also need to include composer's autoloader:

    require_once __DIR__.'/protected/vendor/autoload.php';

Usage

Step 1

To use this extension, just copy this file to your components/ directory, add 'import' => 'application.components.ZRememberGridViewBehavior', [...] to your config/main.php and paste the following code to your behaviors() method of your model

public function behaviors() {
       return array(
           'ZRememberGridViewBehavior' => array(
               'class' => 'application.components.ZRememberGridViewBehavior',
			   'defaults'=>array(),           /* optional line */
			   'defaultStickOnClear'=>false   /* optional line */
           ),
       );
}

Step 2

Your actionAdmin() must not use unsetAttributes() as this was moved to the extension.

With this extension the actionAdmin instead of the classic

        public function actionAdmin()
        {
                $model=new Company('search');
                $model->unsetAttributes();  // clear any default values
                if(isset($_GET['Company']))
                        $model->attributes=$_GET['Company'];
                $this->render('admin',array(
                        'model'=>$model,
                ));
        }

can be as simple as:

        public function actionAdmin()
        {
                $model=new Company('search');
                $this->render('admin',array(
                        'model'=>$model,
                ));
        }

Advanced Functionalities

(if you use these functionalities please Donate)

  • 'defaults' is a key value pair array, that will hold the defaults for your filters. For example when you initially want to display active products, you set to array('status'=>'1'). You can of course put multiple default values in the array.

  • 'defaultStickOnClear'=>true can be used, if you want the default values to be put back when the user clears the filters The default set is false so if the user clears the filters, also the defaults are cleared out, the user will get an absolutely clean filter form. When true, if the form is cleared, he will get a form with defaults values.

Scenarios

(if you use these functionalities please Donate)

You can use scenarios to remember the filters on multiple states of the same model. This is helpful when you use the same model on different views and you want to remember the state separated from each other.
Known limitations: the views must be in different actions (not on the same view)

To set a scenario add the setRememberScenario call after the instantiation
Sample code:

        public function actionAdmin()
        {
                $model=new Company('search');
				$model->setRememberScenario('scene1');
                $this->render('admin',array(
                        'model'=>$model,
                ));
        }

This extension has also a pair Clear Filters Gridview

remember, filters, cgridview, gridview, store, reload, controller, model, behavior, interface, widget, stick, scenario

Change Log

CHANGELOG.md

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my_enhancement_name)
  3. Commit your changes (git commit -am "Added Sorting")
  4. Push to the branch (git push origin my_enhancement_name)
  5. Open a Pull Request
  6. Enjoy a refreshing Diet Coke and wait

yii-remember-gridview's People

Contributors

pentium10 avatar zmiftah avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.