Skip to content

BootstrapTable.prototype.onColumnSearch makes 3 requests #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Oct 26, 2015 · 12 comments
Closed

BootstrapTable.prototype.onColumnSearch makes 3 requests #1605

ghost opened this issue Oct 26, 2015 · 12 comments
Labels
extension Issues for adding or updating our extension.

Comments

@ghost
Copy link

ghost commented Oct 26, 2015

Hi,

Using bootstrap-table-filter-control.js, on server side, 3 requests were sent to server.

Thanks.

@dabros
Copy link
Contributor

dabros commented Oct 27, 2015

@Pilb - more detail please

Ideally include all relevant header and response info from each, or at least url and summary of it so we see what they were

Also please include copy of your html and js related to this plugin

thanks

@ghost
Copy link
Author

ghost commented Oct 27, 2015

Please find example here : https://jsfiddle.net/gr24ouqo/4/.

Try to enter text into column filter and you will see 3 requests on network.

BootstrapTable.prototype.onColumnSearch = function (event) {
        copyValues(this);
        var text = $.trim($(event.currentTarget).val());
        var $field = $(event.currentTarget).parent().parent().parent().data('field')

        if ($.isEmptyObject(this.filterColumnsPartial)) {
            this.filterColumnsPartial = {};
        }
        if (text) {
            this.filterColumnsPartial[$field] = text;
        } else {
            delete this.filterColumnsPartial[$field];
        }

        this.options.pageNumber = 1;
        this.onSearch(event); // First Request
        this.updatePagination(); // Second Request
        this.trigger('column-search', $field, text); // Third Request
    };

Thanks,

Pilb

@wenzhixin wenzhixin added the extension Issues for adding or updating our extension. label Oct 27, 2015
@dabros
Copy link
Contributor

dabros commented Oct 30, 2015

Not much time to look atm, but here is what i found

EDIT i first thought appears to make as many (duplicate) requests as there are columns, even if filter attribute not set on some, as i saw 2 requests only appear after disabling one field, but then saw 3 requests appear again each time later...

Here is updated fiddle: https://jsfiddle.net/dabros/gr24ouqo/5/

I also included https://rawgit.com/wenzhixin/bootstrap-table/master/src/extensions/filter-control/bootstrap-table-filter-control.js inline ('in header no-wrap' option selected) so changes can be quickly modded, though better to fork repo and point to that if you plan on pull request though.

This appears to be where the handlers are added:

if (addedFilterControl) {
            header.off('keyup', 'input').on('keyup', 'input', function (event) {
                clearTimeout(timeoutId);
                timeoutId = setTimeout(function () {
                    that.onColumnSearch(event);
                }, that.options.searchTimeOut);
            });

            header.off('change', 'select').on('change', 'select', function (event) {
                clearTimeout(timeoutId);
                timeoutId = setTimeout(function () {
                    that.onColumnSearch(event);
                }, that.options.searchTimeOut);
            });

            header.off('mouseup', 'input').on('mouseup', 'input', function (event) {
                var $input = $(this),
                oldValue = $input.val();

                if (oldValue === "") {
                    return;
                }

                setTimeout(function(){
                    var newValue = $input.val();

                    if (newValue === "") {
                        clearTimeout(timeoutId);
                        timeoutId = setTimeout(function () {
                            that.onColumnSearch(event);
                        }, that.options.searchTimeOut);
                    }
                }, 1);
            });

            if (header.find('.date-filter-control').length > 0) {
                $.each(that.columns, function (i, column) {
                    if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'datepicker') {
                        header.find('.date-filter-control.' + column.field).datepicker(column.filterDatepickerOptions)
                            .on('changeDate', function (e) {
                                //Fired the keyup event
                                $(e.currentTarget).keyup();
                            });
                    }
                });
            }
        } else {
            header.find('.filterControl').hide();
        }
    };

But that doesnt strike me as wrong at all, so problem prob elsewhere in filter-control code.

@djhvscf might know more, but i cant see anything jumping out at me - next question is can we confirm this relates only to filter-control, and not quirk of base code that either always there or triggered by filter-control interacting like this???

@dabros
Copy link
Contributor

dabros commented Nov 4, 2015

mayble related: #1501

@javieralfaya
Copy link

Hi Dennis,
You have closed this issue and related issue 1501. It has created a patch for this problem?.
Best regards.

@djhvscf
Copy link
Collaborator

djhvscf commented Dec 15, 2015

Until now this issue is opened because we don't have any patch for it.. If you have one please open a new PR @javieralfaya

@javieralfaya
Copy link

Hi Dennis, this is may patch:

Table filter control when pagination on server submit response twice, i commented this.update Pagination(); into bootstrap-table-filter-control.js and problem is resolved:

BootstrapTable.prototype.onColumnSearch = function (event) {
copyValues(this);
var text = $.trim($(event.currentTarget).val());
var $field = $(event.currentTarget).parent().parent().parent().data('field')

if ($.isEmptyObject(this.filterColumnsPartial)) {
    this.filterColumnsPartial = {};
}
if (text) {
    this.filterColumnsPartial[$field] = text;
} else {
    delete this.filterColumnsPartial[$field];
}

this.options.pageNumber = 1;
this.onSearch(event);

//this.updatePagination();
this.trigger('column-search', $field, text);

};

@djhvscf
Copy link
Collaborator

djhvscf commented Dec 15, 2015

Great! Then open a new PR please, @javieralfaya

@dabros
Copy link
Contributor

dabros commented Dec 16, 2015

ioctaptceb pushed a commit to ioctaptceb/bootstrap-table that referenced this issue Jan 27, 2016
There was an incompatibility between the cookies extension and the
filter control extension, which resulted in the following behavior:
every time that a cookie was found, it would be added to a list of
filter, and it would query the database again. This would result in (for
example) a series of three filters to force three separate database
calls, each database call accumulating the last.

This update fixes this issue. it also incorporates the change from issue
 wenzhixin#1605 -- in which updatePagination is called by onSearch(), but both
are included in the onColumnSearch() function, causing the table to
double all calls to the database.
ioctaptceb pushed a commit to ioctaptceb/bootstrap-table that referenced this issue Jan 27, 2016
There was an incompatibility between the cookies extension and the
filter control extension, which resulted in the following behavior:
every time that a cookie was found, it would be added to a list of
filter, and it would query the database again. This would result in (for
example) a series of three filters to force three separate database
calls, each database call accumulating the last.

This update fixes this issue. it also incorporates the change from issue
 wenzhixin#1605 -- in which updatePagination is called by onSearch(), but both
are included in the onColumnSearch() function, causing the table to
double all calls to the database.
@mek-omkar
Copy link

still facing this problem. i am using 1.10.1

@wenzhixin
Copy link
Owner

Please update to 1.11.0

@jmm13
Copy link

jmm13 commented Aug 9, 2018

Still does it in version: 1.12.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension Issues for adding or updating our extension.
Projects
None yet
Development

No branches or pull requests

6 participants