代码之家  ›  专栏  ›  技术社区  ›  Pramod

SPFx-从DetailsList office ui fabric react控件获取所选行数据

  •  0
  • Pramod  · 技术社区  · 2 年前

    我正在使用react类组件开发SPFX Web部件,并希望从DetailsList office ui fabric react控件中获取选定的行数据。我被DetailsList控件中select属性的实现所困扰。你能帮我实现Selection属性吗?

        export default class ProviderWebPartDemo extends React.Component<IProviderWebPartDemoProps, IProviderWebPartDemoState> {
      private _selection: ISelection<IObjectWithKey>;
    
      private _onItemsSelectionChanged = () => {
        
        this.props.onDepartmentSelected(this._selection.getSelection()[0] as IDepartment);
        
        this.setState({
          Department: (this._selection.getSelection()[0] as IDepartment)
        });
    
        
      }
      
      constructor(props: IProviderWebPartDemoProps, state: IProviderWebPartDemoState) {
        super(props);
        this.state = ({
          Department: {
            Id: 0,
            Title: ""
          },
          Deparments: []
        });
        this._selection = new Selection({
          onSelectionChanged: this._onItemsSelectionChanged,
        });  
    
       
      }
    
    <DetailsList
          items={ this.state.Deparments}
          columns={ _departmentListColumns }
          setKey='Id'
          checkboxVisibility={ CheckboxVisibility.always}
          selectionMode={ SelectionMode.single}
          layoutMode={ DetailsListLayoutMode.fixedColumns }
          compact={ true }
          selection={this._selection }                                        
      />
    

    I am stuck with implementation of selection property in the DetailsList control

    上面的代码引发以下错误“类型'Selection'缺少类型'ISelection'中的以下属性:count、mode、canSelectItem、setChangeEvents和18个其他”

    0 回复  |  直到 2 年前