Yii Framework Forum: RRListView - a CListView extension to allow Ajax browser history - Yii Framework Forum

Jump to content

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • You cannot start a new topic
  • You cannot reply to this topic

RRListView - a CListView extension to allow Ajax browser history Rate Topic: -----

#21 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 18 March 2011 - 08:15 AM

View Posthorizons, on 18 March 2011 - 07:28 AM, said:

If you try my modification it is exactly what you mean modifications in the #yw0 part of the url would make changes to the #yw0 widget only.
Just add 2 gridviews on the same page and test it out.


I was talking more about different widgets (or even custom ajax updates).
But I will certainly have a look and get back to you. Unfortunately I'm in the middle of a project at the moment so don't have time to look yet.
Rupert
0

#22 User is offline   horizons 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 18-December 08

Posted 28 March 2011 - 09:19 AM

Updated the gridview js file from yii version 1.1.7 with my bbq modifications.

Still no remarks or suggestions?

Attached File(s)


1

#23 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 29 March 2011 - 03:47 AM

View Posthorizons, on 28 March 2011 - 09:19 AM, said:

Updated the gridview js file from yii version 1.1.7 with my bbq modifications.

Still no remarks or suggestions?


Sorry - I will get back to you - it's just that at the moment I'm in the middle of a project that I need to finish.
Rupert
1

#24 User is offline   pcs2112 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 31-July 10

Posted 16 April 2011 - 05:17 AM

View Posthorizons, on 28 March 2011 - 09:19 AM, said:

Updated the gridview js file from yii version 1.1.7 with my bbq modifications.

Still no remarks or suggestions?


Horizons i think your code is great. 1 last suggestion, please add the code to update the grid using the advance search form :)
0

#25 User is offline   horizons 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 18-December 08

Posted 21 April 2011 - 02:51 AM

@pcs2112 good to hear that my solution also works for others.
But i don't understand your request because if i use the advanced search form on my site the gridview will get rendered correctly and after a successful ajax update the bbq url part is also correctly. And if i use the forward/backwards buttons of my browser the advanced search form options also get the values accordingly.

maybe some code example helps.
<?php

$basepath=Yii::app()->getBasePath();

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('#search-form-outer').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('disseminations-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<div style="margin:10px">
<?php
$searchform = CHtml::link('Advanced Search','#',array('class'=>'search-button'));
$searchform.='<div id="search-form-outer" style="display:none">';
$searchform.='<div id="search-form" class="search-form">';

$searchform.=$this->renderPartial('_search',array(
	'model'=>$model,
    'width'=>'600px'
),true);

$searchform.='</div><!-- search-form -->';  
$searchform.='</div>';

echo $searchform;


$absolute_url=Yii::app()->createAbsoluteUrl('//');
$updateSearchFormscript =<<<EOP

function updateSearchForm(id,result){
    $('.search-form form').submit(function(){
        $.fn.yiiGridView.update(id, {
            data: $(this).serialize()
        });
        return false;
    }); 
}

EOP;

Yii::app()->getClientScript()->registerScript('updateSearchForm',$updateSearchFormscript);

$export_links=CHtml::openTag('div',array('class'=>'exportbuttons'));
$export_links.=CHtml::Link('&nbsp;','',array('class'=>'excelexport tooltipleft','title'=>Yii::t('Global','Export to Excel'),'onclick'=>"location.replace($.param.querystring($.fn.yiiGridView.getUrl('disseminations-grid'),'export=1'));"));
$export_links.=CHtml::closeTag('div');

$pageSize=Yii::app()->user->getState('limit',Yii::app()->params['defaultPageSize']);
$pageSizeSelect=CHtml::openTag('div',array('class'=>'pageSizeSelect'));
$pageSizeSelect.=CHtml::Tag('span',array(),'Items per page:');
$pageSizeSelect.=CHtml::dropDownList('Disseminations[limit]',$pageSize,array(1=>1,5=>5,10=>10,20=>20,50=>50,100=>100),array(
'onchange'=>"$.fn.yiiGridView.update('disseminations-grid',{ data:{limit: $(this).val() }})",
));
$pageSizeSelect.=CHtml::closeTag('div');

$template="<div class='gridviewoptions'>{summary} $pageSizeSelect $export_links <br class=\"clearfloat\" /></div>\n{items}\n{pager}";

Yii::app()->user->setReturnUrl($this->createUrl('admin'));

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'disseminations-grid',
	'dataProvider'=>$model->search(),
    'ajaxUpdate'=>'disseminations-grid,search-form',
    'afterAjaxUpdate'=>'updateSearchForm',
    'filter'=>$model,
    'cssFile'=>Yii::app()->baseUrl .'/css/grid2.css',
    'pager' => array('cssFile' => Yii::app()->baseUrl . '/css/grid2.css'),
    'filter'=>$model,
    'filterPosition'=>'body',
    'template' => $template,
	'columns'=>array(
    --- columns ---
	),
));

?>

</div>

0

#26 User is offline   pcs2112 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 31-July 10

Posted 22 April 2011 - 10:54 PM

awesome thanks for the reply your modification of the yiigridview works perfectly :). I added jquery blocking to make the loading of the grid similar to what you see in google when enterinf a new search or change the page.
0

#27 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 31 May 2011 - 04:22 PM

I'm looking to enable back button with clistview... i think this will work but only for cgridview, not for clistview. Any planing for adding support for that widget?
Give a read to my blog.
0

#28 User is offline   yiqing95 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 586
  • Joined: 27-December 10
  • Location:china

Posted 31 May 2011 - 11:16 PM

View PostRedRabbit, on 29 March 2011 - 03:47 AM, said:

Sorry - I will get back to you - it's just that at the moment I'm in the middle of a project that I need to finish.


if you publish this extension to extension repository ,it will be fine ::)
0

#29 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 01 June 2011 - 02:57 AM

View Postchux, on 31 May 2011 - 04:22 PM, said:

I'm looking to enable back button with clistview... i think this will work but only for cgridview, not for clistview. Any planing for adding support for that widget?


Hello!

I will also upload the same thing for CListView fairly soon, but I don't have the time to do it at the moment because my brother is visiting me.
Rupert
0

#30 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 01 June 2011 - 03:01 AM

Quote

Hello!

I will also upload the same thing for CListView fairly soon, but I don't have the time to do it at the moment because my brother is visiting me.


Hi, thanks for that. I've tested your clistview widget but it doesn't work for me. When i use the pagger, then the links appear to be incorrectly encoded. Some like index.php?r=controller%3ffunction. Seems like it's encoding the /, and then i get an error
Give a read to my blog.
0

#31 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 01 June 2011 - 03:04 AM

Ok, for those impatients :P
Here is the latest version of GridView, which I haven't yet had time to document or package nicely (and no instructions yet).
I will do a proper packagae, and upload as an extension for both ListView and Gridview in the next week or so.

Attached File(s)


Rupert
0

#32 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 01 June 2011 - 09:59 AM

We are impatient for the clistview too!!! lol
Give a read to my blog.
0

#33 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 02 June 2011 - 03:54 PM

Quote

Updated the gridview js file from yii version 1.1.7 with my bbq modifications.

Still no remarks or suggestions?


I have one suggestion, please, do the same for the clistview. Im not very good with js code
Give a read to my blog.
0

#34 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 03 June 2011 - 06:20 AM

Ok, so here are both the CListView and CGridView extensions Attached File  RRViews.zip (13.71K)
Number of downloads: 15.
I haven't yet included any documentation, but they are fairly well commented.

They are perhaps not the perfect solution - it really depends on what you want them for. I have preferred to assume integration between query parameters in the browser bar url and for the ListView/GridView (I'm perhaps obsessed with the symmetry between ajax and non-ajax requests, so I want my querystrings to represent the correct state as a whole as it may be accessed with or without javascript).
This does mean that:
  • you cannot have different listviews/gridviews on the same page that use the same GET parameters (so for two listviews for example, you would have to change the pagination and sorting GET vars for them to work together)
  • all the widgets on the page must be accessed from the same action that generated the page (this can easily be got around but perhaps with a loss of coherence between the different parameters)


I have changed my approach for parsing parameters from updaters - previously I imitated the original js implementation by extracting the parameters from the normal link, and merging them with those in the key link for the widget, perhaps overriding them with parameters from the location querystring or the hash fragment, but I believe this can lead to inconsistencies.
So now, when binding the links, I assume a parameter (which means it is harder to add custom updaters, especially ones which change more than one parameter). Thus for paging links I will only extract the pageVar parameter, and for sorting links likewise.

Handling the input ajax (for the gridview) seems good, with entering text in one input only adding one parameter, and removing text from one not resulting in others being erased.

The hash handling logic is still in a separate javascript file, and could probably do with an overhaul (the error mechanism doesn't work very well), but that will have to come later as it still works.



The advanced search function (which is not actually part of CGridView) can be included in this, simply by manually defining the selector for the input updaters.

So an example of the parameters to add to the widget's construction would be:

'ajaxUpdate' => $searchId,
'inputUpdater' => '#'.$gridId.' .filters input, #'.$gridId.' .filters select, #'.$searchId.' form input, #'.$searchId.' form select',


where $searchId is the id that I have added to the div containing the advanced search form, inputUpdater is the selector for the input elements that should trigger an ajax update (a custom field that I have added, normally calculated automatically in the javascript file, but defined manually here so as to include the inputs from the advanced search form) and $gridId is the id given to the gridview widget.
Adding $searchId to the ajaxUpdate means that whenever the grid is updated, the search form is also updated.
Personally I also think that the submit button should be hidden using javascript, since it has no function here.

I hope this works for you all. Please let me know if there are any bugs.
Once I have ironed everything out I will make it available as an extension.

I should have said - to use, jus unzip into the extensions folder, then for your widget use 'ext.RRListView' etc

This post has been edited by RedRabbit: 03 June 2011 - 06:24 AM

Rupert
0

#35 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 03 June 2011 - 06:22 AM

i will try it in a couple of hours and tell you something
Give a read to my blog.
0

#36 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 03 June 2011 - 09:07 AM

I'm testing your clistview and works very well !!
Thank you
Give a read to my blog.
0

#37 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 03 June 2011 - 10:27 AM

View Postchux, on 03 June 2011 - 09:07 AM, said:

I'm testing your clistview and works very well !!
Thank you


Good to know! Thanks.
Rupert
0

#38 User is offline   pcs2112 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 31-July 10

Posted 04 June 2011 - 12:02 AM

Hi,

they are no working for me.

here is the javascript

jQuery('#yw1').yiiGridView({'ajaxUpdate':['yw1'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'hashHistory':true,'pageVar':'League_page','sortVar':'League_sort'});
});

PHP code

<?php 
$data = $model->search();
$data->pagination->pageSize = $this->module->gridPageSize;

$this->widget('application.extensions.RRGridView.RRGridView', array(
	
	'dataProvider'=>$data,
	'filter'=>$model,
	'columns'=>array(
		array(
			'name' => 'id',
			'type' => 'raw',
			'value' => 'CHtml::link($data->id, $data->getUrl(), array("target" => "self"))',
		),
		'league_name',
		'league_abbr',
		'madden_version',
		'franchiseId',
		'currYear',
		'currSeason',
		'currWeek',
		'state',
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>


these are the js files included in the page

<script type="text/javascript" src="/assets/dc20fa88/gridview/jquery.yiigridview.js"></script>
<script type="text/javascript" src="/assets/9ed78e3e/jquery.rr.hashhandling.js"></script>
<script type="text/javascript" src="/assets/9ed78e3e/jquery.rr.yiigridview.js"></script>

No errors are reported but pagination and sorting don't work, giving my grid an id doesn't help :(
0

#39 User is offline   RedRabbit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 183
  • Joined: 24-September 10

Posted 04 June 2011 - 06:10 AM

Without any error reports it is hard to see what would be causing it - are there no error reports in the Firebug console?
Look in Firebug too to see if the script files were actually downloaded.
The one thing I can think of is that your directory structure might be different - I assume that you unzip the files into the extensions directory so that RRListView.php and RRGridView.php are in the extensions root and the assets subfolder contains the javascript files. That should work by default (as long as the ext alias is defined). If that is not the case then you will have to explicitly give the assets folder to the widget using the extensionAssets parameter, like:

'extensionAssets' => Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.extensions.RRGridView.RRGridView.assets')),

Rupert
0

#40 User is offline   pcs2112 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 31-July 10

Posted 04 June 2011 - 01:31 PM

Its so weird, all the JS files are downloaded but nothing happens when i sort or paginate. The only thing is that the hash symbol is appended to the url.

$this->widget('application.extensions.RRGridView', array( ... ));

Attached File(s)


0

Share this topic:


  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 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