How to check first and last row in GridView

I have custom buttons in GridView and don’t want show some of those reg. first and/or last rows. How can this be achieved in the most effective way?

You need to elaborate more. what is "reg."? What have you tried? Is it the first/last record in the database or the records that are on the page?

Very good point. The records on the page seen by the user are the ones that I’m interested in. So, whatever the order might be according to user input (sorting based on certain column or filtering), I want to hide certain button from first and last row. Was this clear enough? Reg. meant regarding :slight_smile:

You can use css but you can inspect the button, then show it, then click it.




.regButton:first-of-type,.regButton:last-of-type{

 display:none;

}



jQuery




jQuery('.regButton:first-of-type,.regButton:last-of-type').remove();



Data column function




'columns'=>[

 [

 'label'=>''Req',

 'content'=>function($data){

	return $a=$b?''?'button';

  }

 ]

]



I’d use the last way if possible because if the user has javascript disabled then the jquery won’t remove them and they will still be clickable.




'columns'=>[

 [

 'label'=>''Req',

 'content'=>function($data){

	return $a=$b?''?'button';

  }

 ]

]



I didn’t quite get this. What is $a and $b in this example?




'columns'=>[

[

'label'=>''Req',

'content'=>function($data) use $count{

	return ($count = $currentKey)?'':'showButton';

  }

]

]



That was just a short hand if/else for example i added to it but it is overly simplified. If there was a certain value that you attach to the first and last rows to tell php to do something with it i.e. show or not show the button. You could do some math with the dataProvider->count compared to the current row’s key or attach something in your query to the first and last records. There are a few options when doing this.

Ok, got it! Thanks for the info.