jsgrid icon indicating copy to clipboard operation
jsgrid copied to clipboard

sorting & filtering not working in loading by page

Open hrmsandi opened this issue 11 years ago • 2 comments

why sorting & filtering not working in loading by page? any solution?

hrmsandi avatar May 16 '15 11:05 hrmsandi

Filtering should be always implemented by developer. It may be implemented whether on client or server side. On client side we put filtering logic into controller method loadData. On the server side (more common) we pass filter parameters to the server script and apply filtering on server side to avoid transferring of unnecessary data to the client. Thus there is no difference between loading by page and direct loading in case of filtering.

Sorting is really differ for direct loading and loading by page. Direct loading sorts data of the grid. Loading by page strategy just reloads data providing paging parameters to the filter argument of controller loadData method (pageIndex current page index and pageSize - current page size from grid config). Why it happens this way: loading by page makes sense only when you implement all filtering and sorting logic on the server side, when you have big amount of data. Just imagine you've loaded only first page, does it really make sense to sort only this first page items? Sorting of all data can be implemented only on the server side, because grid just don't have other data.

Possible solution Anyway, if you wish sorting of data on the current page, it's doable. All the difference in behavior between loading by page and direct loading is extracted to loadingStrategies (didn't have time yet to describe this advanced info in docs).

    jsGrid.loadStrategies = {
        DirectLoadingStrategy: DirectLoadingStrategy,
        PageLoadingStrategy: PageLoadingStrategy
    };

The direct loading strategy does following on sorting:

    sort: function() {
        this._grid._sortData();
        this._grid.refresh();
        return $.Deferred().resolve().promise();
    }

The loading by page strategy has another implementation:

    sort: function() {
        return this._grid.loadData();
    }

All you need to do is to redefine loading by page strategy behavior (of course, it's possible to create your own loading strategy but it's more complicated than just override sort method):

    jsGrid.loadStrategies.PageLoadingStrategy.prototype.sort = function() {
        this._grid._sortData();
        this._grid.refresh();
        return $.Deferred().resolve().promise();
    }

See following fiddle to see how it works http://jsfiddle.net/tabalinas/z39qvxoc/

tabalinas avatar May 16 '15 14:05 tabalinas

thanks for solution :)

hrmsandi avatar May 17 '15 03:05 hrmsandi