office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
106 lines • 5.44 kB
JavaScript
import * as tslib_1 from "tslib";
import * as React from 'react';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { DetailsList, DetailsListLayoutMode, Selection, DetailsRow, SelectionMode, DetailsRowCheck } from 'office-ui-fabric-react/lib/DetailsList';
import { MarqueeSelection } from 'office-ui-fabric-react/lib/MarqueeSelection';
import { createRef } from 'office-ui-fabric-react/lib/Utilities';
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox';
var _items = [];
var _columns = [
{
key: 'column1',
name: 'Name',
fieldName: 'name',
minWidth: 100,
maxWidth: 200,
isResizable: true,
ariaLabel: 'Operations for name'
},
{
key: 'column2',
name: 'Value',
fieldName: 'value',
minWidth: 100,
maxWidth: 200,
isResizable: true,
ariaLabel: 'Operations for value'
}
];
var DetailsListCustomFooterExample = /** @class */ (function (_super) {
tslib_1.__extends(DetailsListCustomFooterExample, _super);
function DetailsListCustomFooterExample(props) {
var _this = _super.call(this, props) || this;
_this._detailsList = createRef();
_this._onChange = function (ev, text) {
_this.setState({ items: text ? _items.filter(function (i) { return i.name.toLowerCase().indexOf(text) > -1; }) : _items });
};
_this._onShowItemIndexInViewChanged = function (event, checked) {
_this.setState({
showItemIndexInView: checked
});
};
// Populate with items for demos.
if (_items.length === 0) {
for (var i = 0; i < 2; i++) {
_items.push({
key: i,
name: 'Item ' + i,
value: i
});
}
}
_this._selection = new Selection({
onSelectionChanged: function () { return _this.setState({ selectionDetails: _this._getSelectionDetails() }); }
});
_this.state = {
items: _items,
selectionDetails: _this._getSelectionDetails(),
showItemIndexInView: false
};
return _this;
}
DetailsListCustomFooterExample.prototype.render = function () {
var _a = this.state, items = _a.items, selectionDetails = _a.selectionDetails;
return (React.createElement("div", null,
React.createElement("div", null, selectionDetails),
React.createElement("div", null,
React.createElement(Checkbox, { label: "Show index of the first item in view when unmounting", checked: this.state.showItemIndexInView, onChange: this._onShowItemIndexInViewChanged })),
React.createElement(TextField, { label: "Filter by name:", onChange: this._onChange }),
React.createElement(MarqueeSelection, { selection: this._selection },
React.createElement(DetailsList, { componentRef: this._detailsList, items: items, columns: _columns, setKey: "set", layoutMode: DetailsListLayoutMode.fixedColumns, selection: this._selection, selectionPreservedOnEmptyClick: true, ariaLabelForSelectionColumn: "Toggle selection", ariaLabelForSelectAllCheckbox: "Toggle selection for all items", onItemInvoked: this._onItemInvoked, onRenderDetailsFooter: this._onRenderDetailsFooter }))));
};
DetailsListCustomFooterExample.prototype.componentWillUnmount = function () {
if (this.state.showItemIndexInView) {
var itemIndexInView = this._detailsList.current.getStartItemIndexInView();
alert('unmounting, getting first item index that was in view: ' + itemIndexInView);
}
};
DetailsListCustomFooterExample.prototype._getSelectionDetails = function () {
var selectionCount = this._selection.getSelectedCount();
switch (selectionCount) {
case 0:
return 'No items selected';
case 1:
return '1 item selected: ' + this._selection.getSelection()[0].name;
default:
return selectionCount + " items selected";
}
};
DetailsListCustomFooterExample.prototype._onItemInvoked = function (item) {
alert("Item invoked: " + item.name);
};
DetailsListCustomFooterExample.prototype._onRenderDetailsFooter = function (detailsFooterProps, defaultRender) {
return (React.createElement(DetailsRow, { columns: detailsFooterProps.columns, item: {}, itemIndex: -1, groupNestingDepth: detailsFooterProps.groupNestingDepth, selectionMode: SelectionMode.single, selection: detailsFooterProps.selection, onRenderItemColumn: _renderDetailsFooterItemColumn, onRenderCheck: _onRenderCheckForFooterRow }));
};
return DetailsListCustomFooterExample;
}(React.Component));
export { DetailsListCustomFooterExample };
function _renderDetailsFooterItemColumn(item, index, column) {
return (React.createElement("div", null,
React.createElement("span", null,
React.createElement("b", null, column.name))));
}
function _onRenderCheckForFooterRow(props) {
return React.createElement(DetailsRowCheck, tslib_1.__assign({}, props, { style: { visibility: 'hidden' }, selected: true }));
}
//# sourceMappingURL=DetailsList.CustomFooter.Example.js.map