yiiListView: enableHistory does not work when using method .update #2017

Closed
TheHett opened this Issue Jan 20, 2013 · 9 comments

Comments

5 participants

TheHett commented Jan 20, 2013

If enable the option enableHistory

<?php $this->widget('zii.widgets.CListView', array(
    'id'=>'chinchilla-sale',
    'enableHistory'=>true,
    'dataProvider'=>$model->search(),
    'template'=> "{summary}\n{sorter}\n{items}\n{pager}",
    'itemView'=>'_view_sale',
)); ?>

and using update

$('.right-column form').submit(function(){
    $.fn.yiiListView.update('chinchilla-sale', {
        data: $(this).serialize()
    });
    return false;
});

window.location does not changing

Owner

cebe commented Jan 20, 2013

Which browser are you using and which yii version?

Member

mdomba commented Jan 20, 2013

and please explain what would you expect the URL to be changed to...

TheHett commented Jan 21, 2013

Hi,

Browser: Chrome 24.0.1312.52 m
Yii: 1.1.14-DEV (latest)

When I submit form with handler

$('.right-column form').submit(function(){
    $.fn.yiiListView.update('chinchilla-sale', {
        data: $(this).serialize()
    });
    return false;
});

then window url is not changed,
and if after that I using pagination, then page url has changed to

sale.html?ChinchillaSearch[_user_country_id]=&ChinchillaSearch[_user_region_id]=

but it was immediately after pressing submit button

@ghost

ghost commented May 16, 2013

Experiencing the same exact issue. URL is not updated, thus the back button thus comes back to a clean page and does not retain the values of the form.

Member

klimov-paul commented May 16, 2013

"yiiListView::enableHistory" can not affect method "yiiListView.update()" anyhow.
When "yiiListView::enableHistory" is enabled it changes the behavior of sorter and pager links - nothing more.
There is no inbuild method for filtering using browser history in "yiiListView".

You may try to use something like:

function(id, data) {
        var settings = $.fn.yiiListView.settings[id];
        if(settings.enableHistory && settings.ajaxUpdate !== false && window.History.enabled) {
            if (settings.pageVar !== undefined) {
                data += '&' + settings.pageVar + '=1';
            }
            var url = $.fn.yiiListView.getUrl(id);
            var params = $.deparam.querystring($.param.querystring(url, data));
            delete params[settings.ajaxVar];
            window.History.pushState(null, document.title, decodeURIComponent($.param.querystring(url.substr(0, url.indexOf('?')), params)));
        } else {
            $.fn.yiiListView.update(id, {data: data});
        }
    }
@ghost

ghost commented May 18, 2013

Thanks, I'm not sure however where this function is supposed to be executed? On load or on update?

Member

klimov-paul commented May 18, 2013

This function should be called on filter submit.

Here is more precise example:


$('#my-filter-form').onSubmit(function(e) {
    e.preventDefault;
    updateListView('my-list-view-id', this.serialize());
});
function updateListView(id, data) {
        var settings = $.fn.yiiListView.settings[id];
        if(settings.enableHistory && settings.ajaxUpdate !== false && window.History.enabled) {
            if (settings.pageVar !== undefined) {
                data += '&' + settings.pageVar + '=1';
            }
            var url = $.fn.yiiListView.getUrl(id);
            var params = $.deparam.querystring($.param.querystring(url, data));
            delete params[settings.ajaxVar];
            window.History.pushState(null, document.title, decodeURIComponent($.param.querystring(url.substr(0, url.indexOf('?')), params)));
        } else {
            $.fn.yiiListView.update(id, {data: data});
        }
    }
@ghost

ghost commented May 18, 2013

Do I need another JS library? I'm getting $.fn.listViewHistory is undefined

Member

klimov-paul commented May 18, 2013

Sorry, use "yiiListView" instead of "listViewHistory".

TheHett closed this Jul 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment