Skip to content
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

Add custom row rendering #1192

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/documentation/docs/controls/ListView.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The ListView control can be configured with the following properties:
| dragDropFiles | boolean | no | Specify the drag and drop files area option. Default false. |
| onDrop | file | no | Event handler returns files from drag and drop. |
| stickyHeader | boolean | no | Specifies if the header of the `ListView`, including search box, is sticky |
| onRenderRow | (props: IDetailsRowProps) => JSX.Element \| null | no | Callback to override the default row rendering. |
| sortItems | (items: any[], columnName: string, descending: boolean) => any[] | no | Custom sorting function to handle sorting by column |
| className | string | no | Class name to apply additional styles on list view wrapper |
| listClassName | string | no | Class name to apply additional styles on list view |
Expand Down
10 changes: 8 additions & 2 deletions src/controls/listView/IListView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Selection, SelectionMode } from 'office-ui-fabric-react/lib/DetailsList';
import { IColumn, IGroup } from 'office-ui-fabric-react/lib/components/DetailsList';
import {
SelectionMode, IColumn,
IDetailsRowProps, IGroup
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
} from 'office-ui-fabric-react';

export { SelectionMode };

Expand Down Expand Up @@ -68,6 +70,10 @@ export interface IListViewProps {
* Set to false by default
*/
stickyHeader?: boolean;
/**
* Callback to override the default row rendering.
*/
onRenderRow?: (props: IDetailsRowProps) => JSX.Element | null;
/**
* Class name to apply additional styles on list view wrapper
*/
Expand Down
3 changes: 2 additions & 1 deletion src/controls/listView/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
public render(): React.ReactElement<IListViewProps> {
let groupProps: IGroupRenderProps = {};

let { showFilter, filterPlaceHolder, dragDropFiles, stickyHeader, selectionMode, compact, className, listClassName } = this.props;
let { showFilter, filterPlaceHolder, dragDropFiles, stickyHeader, selectionMode, compact, className, listClassName, onRenderRow } = this.props;
let { filterValue, items, columns, groups } = this.state;

// Check if selection mode is single selection,
Expand Down Expand Up @@ -625,6 +625,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
groupProps={groupProps}
className={listClassName}
onRenderDetailsHeader={this._onRenderDetailsHeader}
onRenderRow={onRenderRow}
milanholemans marked this conversation as resolved.
Show resolved Hide resolved
componentRef={ref => {
if (ref) {
ref.forceUpdate();
Expand Down