Skip to content

Commit 2d365c4

Browse files
committed
fix of #648
1 parent 45d255c commit 2d365c4

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

docs/documentation/docs/controls/ListView.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The ListView control can be configured with the following properties:
8484
| Property | Type | Required | Description |
8585
| ---- | ---- | ---- | ---- |
8686
| iconFieldName | string | no | Specify the items' property name that defines the file URL path which will be used to show the file icon. This automatically creates a column and renders the file icon. |
87-
| items | any[]| yes | Items to render in the list view. |
87+
| items | any[] | no | Items to render in the list view. |
8888
| viewFields | IViewField[] | no | The fields you want to render in the list view. Check the `IViewField` implementation to see which properties you can define. |
8989
| compact | boolean | no | Boolean value to indicate if the control should render in compact mode. By default this is set to `false`. |
9090
| selectionMode | SelectionMode | no | Specify if the items in the list view can be selected and how. Options are: none, single, multi. |

src/controls/listView/IListView.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export enum GroupOrder {
99
}
1010

1111
export interface IListViewProps {
12-
/**
13-
* Specify if drag and drop option is selected.
12+
/**
13+
* Specify if drag and drop option is selected.
1414
**/
1515
dragDropFiles?: boolean;
16-
/**
17-
* Handler to return the files from drag and drop.
16+
/**
17+
* Handler to return the files from drag and drop.
1818
**/
1919
onDrop?: any;
2020
/**
@@ -24,7 +24,7 @@ export interface IListViewProps {
2424
/**
2525
* The items to render.
2626
*/
27-
items: any[];
27+
items?: any[];
2828
/**
2929
* The fields you want to view in your list view
3030
*/
@@ -78,7 +78,7 @@ export interface IListViewState {
7878
/**
7979
* The items to render.
8080
*/
81-
items: any[];
81+
items?: any[];
8282
/**
8383
* Given column defitions.
8484
* If none are provided, default columns will be created based on the item's properties.

src/controls/listView/ListView.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IRenderFunction } from 'office-ui-fabric-react/lib/Utilities';
66
import { mergeStyleSets } from 'office-ui-fabric-react/lib/Styling';
77
import { DetailsList, DetailsListLayoutMode, Selection, SelectionMode, IGroup, IDetailsHeaderProps } from 'office-ui-fabric-react/lib/DetailsList';
88
import { IListViewProps, IListViewState, IViewField, IGrouping, GroupOrder } from './IListView';
9-
import { IColumn, IGroupRenderProps } from 'office-ui-fabric-react/lib/components/DetailsList';
9+
import { ConstrainMode, IColumn, IDetailsList, IGroupRenderProps } from 'office-ui-fabric-react/lib/components/DetailsList';
1010
import { findIndex, has, sortBy, isEqual, cloneDeep } from '@microsoft/sp-lodash-subset';
1111
import { FileTypeIcon, IconType } from '../fileTypeIcon/index';
1212
import * as strings from 'ControlStrings';
@@ -74,7 +74,6 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
7474

7575
// Initialize state
7676
this.state = {
77-
items: [],
7877
filterValue: this.props.defaultFilter,
7978
dragStatus: false
8079
};
@@ -260,14 +259,16 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
260259
// Add the columns to the temporary state
261260
tempState.columns = columns;
262261

263-
// Add grouping to the list view
264-
const grouping = this._getGroups(tempState.items, groupByFields);
265-
if (grouping.groups.length > 0) {
266-
tempState.groups = grouping.groups;
267-
// Update the items
268-
tempState.items = grouping.items;
269-
} else {
270-
tempState.groups = null;
262+
if (tempState.items) {
263+
// Add grouping to the list view
264+
const grouping = this._getGroups(tempState.items, groupByFields);
265+
if (grouping.groups.length > 0) {
266+
tempState.groups = grouping.groups;
267+
// Update the items
268+
tempState.items = grouping.items;
269+
} else {
270+
tempState.groups = null;
271+
}
271272
}
272273

273274
// Store the original items and groups objects
@@ -626,13 +627,18 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
626627
if (!props) {
627628
return null;
628629
}
629-
return (
630-
<Sticky stickyPosition={StickyPositionType.Header} isScrollSynced>
631-
{defaultRender!({
632-
...props,
633-
})}
634-
</Sticky>
635-
);
630+
631+
if (this.props.stickyHeader) {
632+
return (
633+
<Sticky stickyPosition={StickyPositionType.Header} isScrollSynced>
634+
{defaultRender!({
635+
...props,
636+
})}
637+
</Sticky>
638+
);
639+
}
640+
641+
return defaultRender!(props);
636642
}
637643
/**
638644
* Default React component render method
@@ -672,7 +678,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
672678
<SearchBox placeholder={filterPlaceHolder || strings.ListViewFilterLabel} onSearch={this._updateFilterValue} onChange={this._updateFilterValue} value={filterValue} />
673679
</SearchBoxWrapper>
674680
}
675-
<DetailsList
681+
{!!items && <DetailsList
676682
key="ListViewControl"
677683
items={items}
678684
columns={columns}
@@ -682,10 +688,15 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
682688
selection={this._selection}
683689
layoutMode={DetailsListLayoutMode.justified}
684690
compact={compact}
685-
setKey="ListViewControl"
691+
setKey='ListViewControl'
686692
groupProps={groupProps}
687693
onRenderDetailsHeader={this._onRenderDetailsHeader}
688-
/>
694+
componentRef={ref => {
695+
if (ref) {
696+
ref.forceUpdate();
697+
}
698+
}}
699+
/>}
689700
</div>
690701
</ListViewWrapper>
691702
);

0 commit comments

Comments
 (0)