Yii Framework Forum: Filtersform, Carraydataprovider - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Filtersform, Carraydataprovider Rate Topic: ***-- 1 Votes

#1 User is offline   Marcolini 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 16-March 12
  • Location:Portugal

Posted 14 January 2013 - 02:04 PM

Hello everyone.

Im doing a CArrayDataProvider manually and adding a filterForm in the easiest way:
$dataProvider = new CArrayDataProvider($arrayTotal, array('keyField'=>'IdSemaforo', 'pagination'=> array('pageSize'=>'15')));
				
			$filtersForm=new FiltersForm;
			if (isset($_GET['FiltersForm']))
				$filtersForm->filters=$_GET['FiltersForm'];
			
			$filteredData = $filtersForm->filter($dataProvider);

			$this->render('admin', array( 'model'=>$dataProvider,
						      'filter'=>$filtersForm));



This works perfectly and filters the way i want.
The problem is that the filters dont filter the exact value, it does some kind of "like"...
Since im creating a CArrayDataProvider, i cant create a criteria. I have no clue how to do this.

There is a screenshot to show what i want. As you see i put systemCode='25' and it shows me all '25's and '25x's... i want the 25s only :/

Appreciate any tips. Thank you

Attached File(s)


0

#2 User is offline   Marcolini 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 16-March 12
  • Location:Portugal

Posted 15 January 2013 - 06:22 AM

bump to the top
0

#3 User is offline   Marcolini 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 16-March 12
  • Location:Portugal

Posted 16 January 2013 - 07:55 AM

Bump to the top
0

#4 User is offline   Marcolini 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 16-March 12
  • Location:Portugal

Posted 16 January 2013 - 11:53 AM

solved :)

just needed to had a compare in FiltersForm Model:
public function filter(array $data)
    {
        foreach($data AS $rowIndex => $row) {
            foreach($this->filters AS $key => $value) {
                // unset if filter is set, but doesn't match
                if(array_key_exists($key, $row) AND !empty($value)) {
		    if (strlen($row[$key]) != strlen($value))
		        unset($data[$rowIndex]);
                    if(stripos($row[$key], $value) === false)
                        unset($data[$rowIndex]);
                }
            }
        }
        return $data;
    }


Comparing the length of the strings:
if (strlen($row[$key]) != strlen($value))
      unset($data[$rowIndex]);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users