-
Notifications
You must be signed in to change notification settings - Fork 934
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
Enable functionality to limit maximum number of rows to select #825
Conversation
Question: How we would like to handle a situation (quite common) when a maximum number of selected rows is lower than a number of rows and a user clicks on the header (select all)? Current behavior: Selects all and unclicking any of row disables this row to be selected again. |
Hello @endrjuskr. Thank you for taking an interest in contributing to the project! I've been thinking about this feature, and I think what I'd like to do instead, is extend the functionality of The advantage this has is that it allows customization based on any logic the dev wants, and it extends an already existing API rather than create a new one. I'm a little wary of creating new APIs if we can use existing ones to do the same job, as I want to be careful about creating an overall API that is so big and complex that it's difficult to reason about and lacks discoverability for those new to the project. How does that sound? |
Sounds reasonable. To be honest, I was not fully convinced about the approach that I proposed, mostly due to selecting all rows from header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking this on. There are a couple things to add before we can merge it, including an additional change needed on line https://github.com/gregnb/mui-datatables/blob/master/src/MUIDataTable.js#L1033 to make sure we're passing in the argument when updating rows:
const selected = isRowSelectable ? isRowSelectable(displayData[i].dataIndex, prevState.selectedRows) : true;
@endrjuskr Almost there! We're still missing the |
Hey @endrjuskr, thanks for the update, however, if you look at the comment, I was actually referring to the test on line 274. :) |
I hope this time I fixed correct test :) Also split one test to check exactly if |
test/MUIDataTableBody.test.js
Outdated
@@ -493,4 +533,69 @@ describe('<TableBody />', function() { | |||
|
|||
expect(html).to.contain('Test_Text'); | |||
}); | |||
|
|||
it('should isRowSelectable be used to determine if row is selectable', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think we can eliminate this test, or recombine it. (or change it as I'll discuss below). It looks like it has a couple of issues once separated out. Mainly, it just seems to be testing whether or not the isRowSelectable
function we create here in the test has the proper return values, which basically means that the test is testing itself. It doesn't test that the table works because it doesn't simulate an interaction with the table select rows.
So, if we just want to show that the function is called, the test below (on line 571) does that, so we could combine it back with that one.
If instead we want to show the positive case, where we demonstrate that a click on a selected row that is allowed by isRowSelectable
works, then I think we should model it after the one on line 274 and simulate the clicks.
I leave it to you as for how you'd like to resolve this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you so much for sticking through it and contributing.
Closes #751.
Interface change: