rstaib / jquery-bootgrid

Nice, sleek and intuitive. A grid control especially designed for bootstrap.
http://www.jquery-bootgrid.com
MIT License
972 stars 362 forks source link

Prevent page reset on data refresh #312

Open Xirt opened 8 years ago

Xirt commented 8 years ago

I was looking into keeping the current page when hitting the "reload"-button, but I noticed that this is currently not possible as Bootgrid resets itself:

     * Resets the state and reloads rows.
     *
     * @method reload
     * @chainable
     **/
    Grid.prototype.reload = function()
    {
        this.current = 1; // reset
        loadData.call(this);

        return this;
    };

Instead, I would like to know whether it is possible to make this reset optional:

     * Resets the state and reloads rows.
     *
     * @method reload
     * @param reset Toggle to reset to the first page (false by default)
     * @chainable
     **/
    Grid.prototype.reload = function(reset)
    {
        // Optionally reset
        this.current = reset ? 1 : this.current;
        loadData.call(this);

        return this;
    };

This can of course have implications as you might get no results if items are removed and the currently selected page is the last one. However, maybe it is possible to work around this problem by using a secondary AJAX-call (e.g. in case the requested page has no results request the last page based on the returned "total").

doodi-v1 commented 8 years ago

I'm having the same issue. Any news?

Xirt commented 8 years ago

I noticed the BootGrid-project is rather inactive (last update a year ago) so I am now updating the library myself to add new features and debug if required by my project. Above appeared to work quite well in most occasions: only in case the number of records has decreased and you were viewing the last page then you might get a blank page as a result (because you load for e.g. page 11 from 10). A secondary query (as suggested) would solve this, but I have not yet changed the code accordingly as the issue is quite small and not very impacting.