Cgridview Column With Chtml::button

hi everyone.

i have got a question. for several days i try to understand how a specific piece of code is generated.

I have got a very dynamic system. Dynamic models and dynmic views. I recieve data from an external source, add several buttons and lead that data to an CGridView.

Here is how i generate those buttons:




		$nav = '';

		$navis = explode(';', $navi);

		foreach($navis as &$n){

			list($name, $folgenr, $filter) = explode(',',$n);

			$config = Config::model()->find(array('nr ==' => $folgenr));

			$filter = explode('|', $filter);

			$nav .= " CHtml::button('$name',

			array(

			'submit' => array('site/dispatch', 'params' => array('nr' => $folgenr, 'filters' => array( ";

			foreach($filter as &$f){

                                $f = strtolower($f);

				$nav .= "'$f'  => " .  '$data[\''. $f .'\'], ';


			}

			$nav .= '), \'breadcrumb\' => \'' . $config->name . '\')))) .';

			

		}

		$nav = substr($nav, 0, strlen($nav)-1). ';';

		$this->result['header'][] = array(

				'name' => 'Buttons',

				'header' => '',

				'type' => 'raw',

				'value' => "$nav",

		);



those buttons are generated well, except the jquery calls. If i recieve an result with more than 10 entries (i guess 10 because 10 is the default page size of CGridView), switch the page to lets say the 2nd page, the buttons will call the controllers with the wrong parameters.

here is the generated jquery code:





/*<![CDATA[*/

jQuery(function($) {

jQuery('#yw1').coolfieldset();

jQuery('#1').yiiGridView({'ajaxUpdate':['1'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'enableHistory':false,'updateSelector':'{page}, {sort}','filterSelector':'{filter}','pageVar':'page'});

jQuery('body').on('click','#yt0',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d33b1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt1',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d3347435dc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt2',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d33c1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt3',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d3789b3cdc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt4',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d3361e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt5',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d34ffd3edc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt6',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d3491e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt7',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d3317435dc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt8',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d34a1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt9',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d3699b3cdc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt10',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d34b1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt11',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d359fd3edc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt12',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d34c1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt13',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d3407435dc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt14',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d34d1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt15',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d3207435dc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt16',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d34e1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt17',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d35c9b3cdc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

jQuery('body').on('click','#yt18',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1100&params%5Bfilters%5D%5Bvc_interessent_obj%5D=PA1029%3ApA%3Acf63c55fdf011a8ddc1104d34f1e2805&params%5Bbreadcrumb%5D=Interessenten+Detail',{});return false;});

jQuery('body').on('click','#yt19',function(){jQuery.yii.submitForm(this,'/abs4webyii/index.php/site/dispatch?params%5Bnr%5D=1300&params%5Bfilters%5D%5Bs_adresse_obj%5D=PA0469%3ApA%3Acf63c55fdf011a8ddc1103d36b9b3cdc&params%5Bbreadcrumb%5D=Interessent+Adresse+Update',{});return false;});

});

/*]]>*/




In that example the result is about 40 entries. Every entry should get 2 buttons. So i thought there might be 80 entries in that jQuery script. The paging doesnt create the jquery calls for the new page in the CGridView.

Where is the fault? Do i something miss in my page-action, in my dataprovider object, in my cgridview?

I hope i could make the problem clear.

I use Yii 1.1.14 and CArrayDataProvider.

EDIT

it depends on pagination size. without pagination i got the expected result with 80 jquery calls. What is going wrong here? I am lost.

EDIT:

Solved it by replacing CHtml::button() with CHtml::beginForm() and CHtml::submitButton(). No JQuery calls are generated.

It is a strange behaviour at all… Is it a Bug?

I have the same problem but the suggested solution doesn’t run. The buttons work correctly only in the first page of the grid.

Instead it runs well if I set [font="Courier New"]ajaxUpdate[/font] to false.

Does someone tell me why? How can I use buttons in grid keeping ajaxUpadate on?