DetailsList with column ratios [Feature Request]
Bug Report
- Package version(s): 2.10.4
- Browser and OS versions: (fill this out if relevant)
Priorities and help requested (not applicable if asking question):
Are you willing to submit a PR to fix? No
Requested priority: Normal
Products/sites affected: (if applicable)
Describe the issue:
Currently the DetailsList columns width either go with the minWidth or the maxWidth, it doesn't not change on different screen sizes.
We want to add a new property to IColumn to set the default width ratio so the width can be set dynamically.
Added some code samples on calculation of adjusted width
@@ -536,13 +552,14 @@ export class DetailsList extends React.Component<IDetailsListProps, IDetailsList
private _getJustifiedColumns(newColumns: IColumn[], viewportWidth: number) {
let {
selectionMode,
- groups
+ groups,
+ isContentContainerScrollable
} = this.props;
let outerPadding = DEFAULT_INNER_PADDING;
let rowCheckWidth = (selectionMode !== SelectionMode.none) ? CHECKBOX_WIDTH : 0;
let groupExpandWidth = groups ? GROUP_EXPAND_WIDTH : 0;
let totalWidth = 0; // offset because we have one less inner padding.
- let availableWidth = viewportWidth - outerPadding - rowCheckWidth - groupExpandWidth;
+ let availableWidth = viewportWidth - outerPadding - rowCheckWidth - groupExpandWidth - (isContentContainerScrollable ? getScrollbarWidth() : 0);
let adjustedColumns: IColumn[] = newColumns.map((column, i) => {
let newColumn = assign(
{},
@@ -570,13 +587,26 @@ export class DetailsList extends React.Component<IDetailsListProps, IDetailsList
}
// Then expand columns starting at the beginning, until we've filled the width.
+
+ // expand according to default ratio
+ let ratioSum: number = newColumns
+ .map(column => (column.defaultWidthRatio ? column.defaultWidthRatio : 0))
+ .reduce((previousValue, currentValue) => (previousValue + currentValue), 0);
+
for (let i = 0; i < adjustedColumns.length && totalWidth < availableWidth; i++) {
let column = adjustedColumns[i];
let maxWidth = column.maxWidth;
let minWidth = column.minWidth || maxWidth || MIN_COLUMN_WIDTH;
let spaceLeft = availableWidth - totalWidth;
+
let increment = maxWidth ? Math.min(spaceLeft, maxWidth - minWidth) : spaceLeft;
+ let preferredWidth: number = column.defaultWidthRatio ?
+ Math.floor((availableWidth - (DEFAULT_INNER_PADDING * (adjustedColumns.length - 1))) * (column.defaultWidthRatio / ratioSum)) : 0;
+ if (preferredWidth && preferredWidth - minWidth < increment) {
+ increment = preferredWidth - minWidth;
+ }
+
// Add remaining space to the last column.
if (i === (adjustedColumns.length - 1)) {
increment = spaceLeft;
Thanks
Actual behavior:
Expected behavior:
If applicable, please provide a codepen repro:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Fabric React!
This issue has been automatically closed because it has not had recent activity after being marked as stale. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to Fabric React! Why am I receiving this notification?