2017-08-29 59 views
0

我想在Create,Edit頁面內創建一個Datagrid來顯示和管理n-to-n關係。但我不知道如何將props轉換爲ListDatagrid以及props應該通過。Datagrid在創建,編輯頁面

管理這個Datagrid的資源名爲caregiver_student,我把它放在我自定義的restClient文件中。

基本信息 Basic info

相關信息 Relationship info

這裏是我的代碼:

<Edit title={<CaregiverTitle />} {...props}> 
    <TabbedForm> 
     <FormTab label="Personal Info"> 
      <DisabledInput source="id" /> 
      <TextInput source="name" /> 
      <TextInput source="email" /> 
      <TextInput source="phone" /> 
      <RadioButtonGroupInput source="account_type" choices={[ 
       { id: 10, name: 'Caregiver' }, 
       { id: 20, name: 'Guardian' }, 
      ]} optionText="name" optionValue="id" /> 
      <BooleanInput source="status" label="Active"/> 
     </FormTab> 
     <FormTab label="Relationship"> 
      <List actions={<RelationActions/>} location={false} title={" "}> 
       <Datagrid> 
        <TextField source="id" /> 
        <TextField source="name" label="Student"/> 
        <TextField source="relationship" /> 
        <EditButton /> 
        <DeleteButton /> 
       </Datagrid> 
      </List> 
     </FormTab> 
    </TabbedForm> 
</Edit> 

謝謝您的幫助!

回答

0

我有一個類似的頁面,其中列出了屬於特定「批次ID」的「Batchunits」。

<FormTab label="resources.batches.tabs.batchunits"> 
    <ReferenceManyField addLabel={false} reference="Batchunits" target="batchid"> 
     <Datagrid bodyOptions={{ stripedRows: true, showRowHover: true}} > 
      <TextField source="unitcode" /> 
      <DateField source="harvested" /> 
      <BooleanField source="contaminated" label="Contaminated"/> 
      <TextField source="note" style={{ maxWidth: '10em', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }} /> 
      <EditUnitButton /> 
     </Datagrid> 
    </ReferenceManyField> 
</FormTab> 

但在此設置中,Formtab將不會接受創建「按鈕」來創建另一個資源的記錄。例如另一個「Batchunit」,創建另一個鏈接Batchunit會非常有用,不知道該怎麼做......

+0

目前還不支持這個功能,有人開始了一個可能有所幫助的PR:https://github.com/marmelab/admin-on-rest /拉/ 744 – Gildas