Skip to content
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

'refresh' method doesn't reuse parameters provided as "query", it only takes "url". #7318

Open
utilmind opened this issue May 4, 2024 · 11 comments · May be fixed by #7353
Open

'refresh' method doesn't reuse parameters provided as "query", it only takes "url". #7318

utilmind opened this issue May 4, 2024 · 11 comments · May be fixed by #7353
Labels
Bug Issues which are marked as Bug confirmed Issues that have been confirmed with a reduced test case and identify a bug. has PR Issues that has been fixed with a PR.

Comments

@utilmind
Copy link
Contributor

utilmind commented May 4, 2024

Bootstraptable version(s) affected

1.22.5 (latest)

Description

Unfortunately "refresh" button on toolbar is useless, if I originally provide the request parameters as "query" property, instead of straightforward GET-query, as part of "url" property.

So if I originally provide data as follows, this will not work on manual "refresh" (click on refresh button on toolbar), it will just ignore "query" on repeating request:

$table.bootstrapTable('refresh', {
                            url: thisToolUrl,
                            query: prepareHttpQuery(),
                        });

However, the following will work:

$table.bootstrapTable('refresh', {
                            // httpBuildQuery converts array to &-separated and urlencoded 'key=value' pairs.
                            url: thisToolUrl + '?' + httpBuildQuery(prepareHttpQuery()), 
                        });

I think it should not ignore data provided in "query" on repeating "refreshes".
The workaround provided above is works for me, so I don't submitting the pool request, but would switch to "query" if it will be fixed in further Bootstrap Table versions.

Example(s)

No response

Possible Solutions

Fix initServer() method, reuse saved "query" parameter from previous "refresh" request.

Additional Context

No response

@utilmind utilmind added the Bug Issues which are marked as Bug label May 4, 2024
@utilmind utilmind changed the title 'refresh' method doesn't reuse parameters ("query"), it only takes "url". 'refresh' method doesn't reuse parameters provided as "query", it only takes "url". May 4, 2024
@wenzhixin
Copy link
Owner

Please provide an Online Example to show your problem. Thanks!

@wenzhixin wenzhixin added needs example Need an example in order to confirm the issue or the PR. awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. labels May 7, 2024
@UtechtDustin
Copy link
Collaborator

We will close this issue as we got no response form you. If you still need help with that please provide us an example as @wenzhixin said.

@utilmind
Copy link
Contributor Author

utilmind commented May 26, 2024

@UtechtDustin -- We will close, or already closing?
In either case, it's can't be closed as "Completed". It's not completed.

@utilmind
Copy link
Contributor Author

utilmind commented May 26, 2024

@wenzhixin here you go
https://live.bootstrap-table.com/code/utilmind/17717
There are 2 buttons in example. First specifying parameters in documented 'query' property (this example doesn't works), second specifying parameter(s) directly in the 'url' (this works).

@UtechtDustin please don't close the issue as “Completed” immediately after reminder. This is extremely discouraging.

@utilmind
Copy link
Contributor Author

Just in case, here is the source code of PHP script which generating content for my example on https://live.bootstrap-table.com/code/utilmind/17717

<?php

if (isset($_GET['required-parameter'])) {
    $out = [
        [
            'id' => 1,
            'name' => 'name1',
            'price' => 123.45,
        ],
        [
            'id' => 2,
            'name' => 'name2',
            'price' => 543.21,
        ],
    ];

}else {
    $out = [];
}

// No cache
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.date('r'));
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('X-Robots-Tag: noindex, nofollow, noarchive');
// Allow at least live.bootstrap-table.com
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
// Output JSON
header('Content-type: application/json');
exit(json_encode($out, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));

@utilmind
Copy link
Contributor Author

utilmind commented May 26, 2024

As I mentioned in my top comment, I'm not contributing the fix for this issue because a workaround with ?parameters= in the url works pretty well for me, although this is obviously wrong that query is ignored in the refresh method and could be issue for someone else.

@UtechtDustin
Copy link
Collaborator

Sorry, my bad. I don't know that the close button marks it as completed or that there is a close option without out the completed part.

@UtechtDustin UtechtDustin reopened this May 26, 2024
@UtechtDustin
Copy link
Collaborator

The query option of the refresh method is internally almost the same as the queryparams table option.
Which means you have to define the query as Object, as documented on both options.
Bildschirmfoto 2024-05-26 um 23 56 23

Working demo: https://live.bootstrap-table.com/code/UtechtDustin/17720

@UtechtDustin UtechtDustin added help-wanted Issues we need or would love help from the community to resolve. and removed needs example Need an example in order to confirm the issue or the PR. Bug Issues which are marked as Bug labels May 26, 2024
@utilmind
Copy link
Contributor Author

@UtechtDustin Okay, yes, my bad I specified the query incorrectly in my example, but it was correct in my real app.

Here is another example: https://live.bootstrap-table.com/code/utilmind/17722
It uses your fix + little improvement, "refresh" button in toolbar.

  1. Try to load data with the first, [Refresh using 'query'] button. Then try to reload data with "refresh" button at the top-right side of table. This will not work. Data specified in query will not be preserved, it will not be used for native refresh.
  2. However, if you load the data using only URL, with the second button, URL will be used upon native refresh.
    (Click second button, then reload data with "refresh" button at the top-right — second case works.)

@UtechtDustin
Copy link
Collaborator

You're right!
if a url is passed to the refresh method the url will be set as new "base"-url, which means if we have a url with parameters the parameters are also the new default value.
If we pass the query they are only used for the next request.
https://github.com/wenzhixin/bootstrap-table/blob/develop/src/bootstrap-table.js#L3094-L3106

That should be an easy fix, as soon we get a query object we have to add/merge it to our base url.

@UtechtDustin UtechtDustin added confirmed Issues that have been confirmed with a reduced test case and identify a bug. Bug Issues which are marked as Bug and removed awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. help-wanted Issues we need or would love help from the community to resolve. labels May 27, 2024
@UtechtDustin UtechtDustin linked a pull request May 27, 2024 that will close this issue
10 tasks
@UtechtDustin UtechtDustin added the has PR Issues that has been fixed with a PR. label May 27, 2024
@UtechtDustin
Copy link
Collaborator

Should be fixed by #7353.
Working example with the fix: https://live.bootstrap-table.com/code/UtechtDustin/17731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues which are marked as Bug confirmed Issues that have been confirmed with a reduced test case and identify a bug. has PR Issues that has been fixed with a PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants