-
Notifications
You must be signed in to change notification settings - Fork 7
feat(oui-datagrid): add selectable rows #242
Conversation
packages/oui-datagrid/README.md
Outdated
### Global Actions | ||
|
||
```html:preview | ||
<oui-datagrid rows="$ctrl.data" page-size="5" global-actions> |
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.
Wouldn't it be best to name the parameter "selectable-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.
sounds good
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.
Yes, selectable-rows
is better :)
Don't forget to add the details in the API table below for this attribute
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.
Were it only me, I would have named it allows-row-selection
but I know you guys won't like it 😄
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.
In this way, we keep our logic of *able attributes
this.displayedRows = DatagridController.createEmptyRows(this.paging.getCurrentPageSize()); | ||
} | ||
|
||
this.selectedRows = this.selectedRows.map(() => 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.
Can't this contain the actual rows instead of an array of booleans ? Or something to identify the rows ?
{
id: rowId,
isSelected: false
}
If we keep the array of booleans system, then it should be names something like rowSelectionStatus
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.
since every checkbox needs to have an ng-model i still have to created N booleans for binding ; that's why it made sense to use an array of booleans (i reuse the array)
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.
We could react to the checkbox's on-change
event and add the corresponding row to the array of 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.
i think your suggestion would make the code "faster" : no reduce in getSelectedRows since you access array directly ; downside is that you need an additionnal array to store rows which is less clean (you still have to give an ngModel to checkbox so you also need an array of booleans).
did i understand you correcly ?
}, []); | ||
} | ||
|
||
onSelectRow (index, selected) { |
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.
onRowSelection
? Still feels wrong as this method is called even when the row is unselected
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.
onToggleSelectRow would be better i think
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.
Yes, good name !
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.
In this case, toggleRowSelection
seems more appropriate
}, []); | ||
} | ||
|
||
onSelectRow (index, selected) { |
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.
selected
could be named isSelected
, so we know it's a boolean
} else if (selectedRowsCount === 0) { | ||
this.selectAllRows = false; | ||
} else { | ||
this.selectAllRows = null; |
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.
Is this the global comportement for tri-select box ? null
is some items are selected, some are not
? Because, if it's not already the selected behavior, this would require a something else than a boolean then
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.
yep checkbox component currently use "null"
} | ||
} | ||
|
||
toggleSelectAllRows (modelValue) { |
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.
currentSelectionStatus
?
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.
We could keep the same logic as above, toggleAllRowsSelection
@frenautvh I've only commented because I feel most point would require a discussion |
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.
Some improvements needed, but seems good.
Don't forget the unit tests and the documentation :)
packages/oui-datagrid/README.md
Outdated
### Global Actions | ||
|
||
```html:preview | ||
<oui-datagrid rows="$ctrl.data" page-size="5" global-actions> |
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.
Yes, selectable-rows
is better :)
Don't forget to add the details in the API table below for this attribute
this._compileCell(); | ||
} | ||
|
||
this.index = this.index || 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.
Should be in $onInit
}, []); | ||
} | ||
|
||
onSelectRow (index, selected) { |
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.
In this case, toggleRowSelection
seems more appropriate
} | ||
} | ||
|
||
toggleSelectAllRows (modelValue) { |
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.
We could keep the same logic as above, toggleAllRowsSelection
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.
@frenautvh From the staging, the first column is not fixed. Can you check it ?
Caution on your CDS builds too :)
} | ||
|
||
this.cellScope.$watch(() => this.datagridCtrl.selectedRows[this.index], (isSelected) => { | ||
this.cellScope.$isSelected = 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.
this.cellScope.$isSelected = !!isSelected
is possible no ?
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.
!!
is harder to read by someone not used to this js "trick" but yes it would fit the job
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.
Ok :)
@antleblanc @euhmeuh @FredericEspiau |
@frenautvh @antleblanc @euhmeuh @FredericEspiau @JeremyDec |
@AxelPeter I'm targeting that kind of comments :
Example :
|
I know and I agree, that's why I suggest some methods to everybody for working together (it works with our previous team) ;) |
UK-42