-
Notifications
You must be signed in to change notification settings - Fork 105
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
Select all rows (include group rows) in the journal grid #1526
Select all rows (include group rows) in the journal grid #1526
Conversation
Select and unselect group rows
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.
@mbayopanda, I've made some comments for code clarity.
@@ -21,6 +21,7 @@ function GridGroupingService(GridAggregators, uiGridGroupingConstants, Session, | |||
$timeout, util, uiGridConstants) { | |||
/** @const aggregators assigned by column ids */ | |||
var DEFAULT_AGGREGATORS = GridAggregators.aggregators.tree; | |||
var SELECTED_GROUP_HEADERS; |
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.
The ALL_CAPITAL_LETTERS syntax is usually for constants. Does this variable need to be global to the entire service? It looks like it is only used in hadnleBatchSelection()
.
// handle deselect | ||
if (hasSelections === false) { | ||
angular.forEach(SELECTED_GROUP_HEADERS, function (node) { | ||
node.isSelected = false; |
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.
What does isSelected
do? It looks like it is always set but never used. Is it an internal ui-grid
thing?
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.
The isSelected
is responsible to set the row selected (checked) in the ui grid.
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.
Cool - I was wondering if that was the case 👍
if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) { | ||
parentRow.isSelected = true; | ||
parents[parentRow.uid] = parentRow; | ||
SELECTED_GROUP_HEADERS = parents; |
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.
Do you need to set this every loop through the gridRows
? It looks like what you are really doing is:
gridRows.forEach(function (row) {
var parentRow = row.treeNode.parentRow;
if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) {
parentRow.isSelected = true;
parents[parentRow.uid] = parentRow;
}
});
SELECTED_GROUP_HEADERS = parents;
If that is true, then it is easier to read (and might be more performant) to remove the SELECTED_GROUP_HEADERS
variable assignment from the loop.
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.
the SELECTED_GROUP_HEADERS
is a global variable and must be updated only when there are new parent row (enter in the if
clause).
If it is out the if
we cannot deselect parent rows which were previously selected because
var parents = {};
/* this code is not executed
gridRows.forEach(function (row) {
var parentRow = row.treeNode.parentRow;
if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) {
parentRow.isSelected = true;
parents[parentRow.uid] = parentRow;
}
}); */
SELECTED_GROUP_HEADERS = parents; // SELECTED_GROUP_HEADERS = {}
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.
Aha, that makes sense. I don't think there is a clearer way of expressing what you wrote. LGTM 👍
|
||
gridRows.forEach(function (row) { | ||
var parentRow = row.treeNode.parentRow; | ||
if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) { |
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.
I know what this is because we've talked about it, but the code is hard to read as it is. Could you move this check into a function?
// this function identifies parent rows that we haven't seen yet
function isUnusedParentRow(row) {
return row.treeLevel === 0 && !parents[row.uid];
}
gridRows.forEach(function (row) {
var parentRow = row.treeNode.parentRow;
if (isUnusedParentRow(parentRow)) {
// do something.
}
});
var gridRows = gridApi.selection.getSelectedGridRows(); | ||
var parents = {}; | ||
|
||
var hasSelections = gridApi.selection.getSelectedRows().length > 0; |
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.
Nice variable assignment 👍
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.
All my comments have been addressed 👍
…into select_all_journal
This PR permits to select all rows in the journal grid, this selection include the group header rows.
Closes #1512.