admin管理员组文章数量:1356024
I am trying to make a table with Material UI Table, and when I edit or add a row some values are to be selected from a dropdown. That works as expected, but I would like to have one of the dropdown values as a default when creating a new row, instead of just being an empty value as it is now.
This is my table
const table = useMaterialReactTable({
data: data ?? [],
columns: useMemo(() => [
{
header: 'Name',
accessorKey: 'name',
editable: 'onAdd',
width: 200,
muiEditTextFieldProps: {
placeholder: 'Name'
}
},
{
header: 'Dropdown',
accessorKey: 'dropdown',
editVariant: 'select',
editSelectOptions: dropdown_values,
filterVariant: 'select',
filterSelectOptions: dropdown_values,
muiEditTextFieldProps: {
value: staff_department
},
width: 200,
},
], [dropdown_values]),
createDisplayMode: 'row',
editDisplayMode: 'row',
enableEditing: true,
onCreatingRowSave: async ({ table, values }) => {
await createNewRow(values);
table.setCreatingRow(false);
},
onEditingRowSave: async ({ table, row, values }) => {
await updateRow({...row.original, ...values});
},
renderRowActions: ({ row, table }) => (
<TableRowControls
onEdit={ () => table.setEditingRow(row) }
/>
),
displayColumnDefOptions: {
'mrt-row-actions': {
visibleInShowHideMenu: false
}
},
enableDensityToggle: false,
enableFullScreenToggle: false,
state: {
density: 'compact'
},
renderTopToolbarCustomActions: ({ table }) => (
<div>
<CreateButton onClick={ () => table.setCreatingRow(true) }/>
</div>
),
});
Is it possible to add a defaultValue for the dropdown?
Thanks for helping
版权声明:本文标题:javascript - Is it possible to set a default value for an Material React Table with a select - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744037337a2580018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论