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

getSelections Method fails to maintain all selected rows #7448

Open
odfwalemay opened this issue Aug 2, 2024 · 2 comments
Open

getSelections Method fails to maintain all selected rows #7448

odfwalemay opened this issue Aug 2, 2024 · 2 comments
Labels
Bug Issues which are marked as Bug

Comments

@odfwalemay
Copy link

Bootstraptable version(s) affected

1.23.2

Description

When calling the "getSelections" method no items are returned when table is paged or filtered (it only returns what is on the first page).

Worse, when removing the filter, it loses all selected rows except those on the first page (if there are no rows selected on the first page, all selected rows are lost)

Example(s)

https://examples.bootstrap-table.com/#methods/get-selections.html

Simply use the example setup for method call:
Steps

  1. Go to Url above
  2. Check Item ID 4
  3. Click button - shows selections (Item ID: 4)
  4. Enter "5" in the search field
  5. Selected row disappears since it does not match
  6. Click button - nothing is selected any longer
  7. Clear the search field
  8. Click button - nothing

Note: The checked Item ID 4 is no longer checked - so clearing the filter has cleared the selected rows!!!

Possible Solutions

No response

Additional Context

No response

@odfwalemay odfwalemay added the Bug Issues which are marked as Bug label Aug 2, 2024
@OnlyPassionCode
Copy link

This is not a bug, check this page:
https://examples.bootstrap-table.com/index.html#options/maintain-meta-data.html

Use maintainMetaData option to maintain the meta data(selected rows and hidden rows) on change page and search.

@odfwalemay
Copy link
Author

odfwalemay commented Aug 6, 2024

I believe I have found the issue.

If you place a data formatter on the column the getSelections will work inconsistently within the context of the current page for the given table. If you go to the example noted in my posting for the getSelections, add the following properties to the table:
data-pagination="true"
data-page-size="10"
data-maintain-meta-data="true"

Update the table:
th data-field="state" data-checkbox="true" data-formatter="isChecked"

Then go to the "script" section and add:
var ids = [4, 14];

function isChecked(value, row) {
return ids.includes(row.id);
}

When the getSelections button is clicked, you will note that it does NOT contain the data from page 2 for "id = 14", even though it is selected. If you navigate to the second page to verify that the item for "id = 14" is checked, press the getSelections button again, and it now appears to have both items.

Now, go back to the first page and check ID 6 and click the getSelections button. Seems fine. Navigate to the second page and unselect ID 14 and click the getSelections button. Seems fine. Return to the first page and ID 6 is no longer checked. Click the getSelections button again and it contains both ID 4 and 6.

Premise for the bug was... I loaded a list of IDs which belong to an entity, say a Dealership. The IDs represent the cars which are currently on the lot. A table is then filled with a property on the Dealership called Cars, but Cars represent all cars the dealership owns. So the data formatter is used to set the state based on if the Car's ID is in the list of IDs (similar to the function above) to show which Car is currently on the lot for the Dealership. The user has received notice that Car ID 32 is now on the lot and wishes to update the table by checking the box. The user also receives notices that another Car has arrived at the lot as well, ID 54. So the user navigates say to page 3 (25 per page), checks that box. The user clicks a "Save" button. The action for the save simply goes to the table and calls the getSelections as this should have a list of all the data rows which have a "checked" state. But that state appears to be volatile and not being properly maintained. (As if the bug is in the maintain meta data functionality).

I hope this helps better explain the issue, or heck, I might not be approaching the solution properly given the example just above.

Please advise. Thanks.

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
Projects
None yet
Development

No branches or pull requests

2 participants