“创建”,“编辑”页面中的数据网格

时间:2017-08-29 05:02:47

标签: admin-on-rest

我想在DatagridCreate页面中创建Edit以显示和管理n-to-n关系。但我不知道如何将props传递给ListDatagrid以及props应该传递的内容。

用于管理名为caregiver_student的此Datagrid的资源,并将其放入我的自定义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>

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

链接的资源应包含在ReferenceManyField

您可以在演示中找到完整的示例,  特别是Customers Edit component

有人开了一个可能有帮助的公关:https://github.com/marmelab/admin-on-rest/pull/744

答案 1 :(得分:0)

我有一个类似的页面,其中的标签列出了&#34; Batchunits&#34;属于特定&#34; batchid&#34;。

<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将不接受创建&#34;按钮&#34;创建另一个资源的记录。例如另一个&#34; Batchunit。创建另一个链接的Batchunit非常有用。不知道该怎么做......