Cgridview

Good day guys, I have a simple cgridview for my admin page that display all the records. But I want to hide/skip the first record that it will display or start the cgridview with the 2nd record. Thank you in advance.

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'shis-medinventory-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	'med_name',


	'med_desc',


	array(


		'name'=&gt;'medType.mtype_name',


		'filter'=&gt;CHtml::activeTextField(&#036;model,'medType_search'),


	),


	array(


		'class'=&gt;'CButtonColumn',


			'template'=&gt;'{view}{update}{delete}',


			'buttons'=&gt;array(


                   'view'=&gt; array(


                        'url'=&gt;'Yii::app()-&gt;createUrl(&quot;shisMedinventory/view&quot;, array(&quot;id&quot;=&gt;&#036;data-&gt;med_id))',


                   ),


                   'update'=&gt; array(


                        'url'=&gt;'Yii::app()-&gt;createUrl(&quot;shisMedinventory/update&quot;, array(&quot;id&quot;=&gt;&#036;data-&gt;med_id))',


                   ),


                   'delete'=&gt; array(


                        'url'=&gt;'Yii::app()-&gt;controller-&gt;createUrl(&quot;shisMedinventory/delete&quot;,array(&quot;id&quot;=&gt;&#036;data-&gt;primaryKey))',


					'visible'=&gt;&#036;visStatus,	


                        ),


                   )


	),


),

)); ?>

Maybe you can set the ‘offset’ of the CDbCriteria to 1 in the model::search() method.

Not tested, you have to check what happens on pagination.





public function search()

	{


		$criteria=new CDbCriteria;


                $criteria->offset = 1;  


		$criteria->compare(...);

                ...

        }  




Because of curiosity…

what problem do u have with first record :)

why you dont need first item

tnx for the reply, but sad to say it didnt work

haha, you see that cgridview consist of medicine records. it was use to fill the list of data of dropdownlist in my form consultation and the first item has value no data the second row will be the first medicine. upon loading the adminpage for medicine i dont want the admin to see the no data row and starts the record with the medicine. sorry for my bad english :)

can u give ur screen schot…

do u want to remove first row from cgridview or dropdownlist ?

Ok, I took a look at Yii source code.

This does only works without pagination when you set the dataproviders pagination=false.

The pagination handling of the dataprovider adds always a offset 0, 10, … on fetching data when pagination is set. Even a model or criteria scope with ‘offset’=>1 will not work.

So I can’t see a solution out of the box without using your own dataprovider/pagination overriding the CActiveDataprovider/CPagination.

In you case it should be easy to add a condition to filter the ‘not medicine’

in the search method:




 $criteria->addCondition(... is not a medicine ...);

 ...

 $criteria->addCondition('id=0');

 ...

 $criteria->addCondition('title is null');  




otherwise you can extend the grid view and during rendering rows make some counter increments by 1 and check whether counter is 1 or not if it is 1 then ignore it

tnx for ur reply, well this is the screen shot of the page.

I want to hide that from the list because i want to prevent the user to update/edit that specific data.

can you please show me this is my code

public function search()

{


	// @todo Please modify the following code to remove attributes that should not be searched.





	&#036;criteria=new CDbCriteria;


	&#036;criteria-&gt;compare('med_id',&#036;this-&gt;med_id);


	&#036;criteria-&gt;compare('med_name',&#036;this-&gt;med_name,true);


	&#036;criteria-&gt;compare('med_desc',&#036;this-&gt;med_desc,true);


	&#036;criteria-&gt;compare('med_typeid',&#036;this-&gt;med_typeid);


	&#036;criteria-&gt;compare('med_flag',&#036;this-&gt;med_flag);


	


	&#036;criteria-&gt;with=array('medType');


	&#036;criteria-&gt;compare('medType.mtype_name',&#036;this-&gt;medType_search, true);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


	


	/* PAGINATION


	return new CActiveDataProvider(get_class(&#036;this), array(


		'criteria' =&gt; &#036;criteria,


		'pagination' =&gt; false,


		));


		*/


}

can you please show me this is my code

public function search()

{


	// @todo Please modify the following code to remove attributes that should not be searched.





	&#036;criteria=new CDbCriteria;


	&#036;criteria-&gt;compare('med_id',&#036;this-&gt;med_id);


	&#036;criteria-&gt;compare('med_name',&#036;this-&gt;med_name,true);


	&#036;criteria-&gt;compare('med_desc',&#036;this-&gt;med_desc,true);


	&#036;criteria-&gt;compare('med_typeid',&#036;this-&gt;med_typeid);


	&#036;criteria-&gt;compare('med_flag',&#036;this-&gt;med_flag);


	


	&#036;criteria-&gt;with=array('medType');


	&#036;criteria-&gt;compare('medType.mtype_name',&#036;this-&gt;medType_search, true);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}

tnx for the reply sir, but i dont have any idea how to do that :) . can you please show me bacause i am very new in yii.