Skip to main content
Version: 3.xx.xx

Delete

<DeleteButton> uses Mantine <Button> and <Popconfirm> components. When you try to delete something, a pop-up shows up and asks for confirmation. When confirmed it executes the useDelete method provided by your dataProvider.

Usage​

http://localhost:3000
import { List, Table, Pagination, DeleteButton } from "@pankod/refine-mantine";
import { useTable, ColumnDef, flexRender } from "@pankod/refine-react-table";

const PostList: React.FC = () => {
const columns = React.useMemo<ColumnDef<IPost>[]>(
() => [
{
id: "id",
header: "ID",
accessorKey: "id",
},
{
id: "title",
header: "Title",
accessorKey: "title",
},
{
id: "actions",
header: "Actions",
accessorKey: "id",
cell: function render({ getValue }) {
return (
<DeleteButton
size="xs"
recordItemId={getValue() as number}
/>
);
},
},
],
[],
);

const {
getHeaderGroups,
getRowModel,
refineCore: { setCurrent, pageCount, current },
} = useTable({
columns,
});

return (
<List>
<Table>
<thead>
{getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</th>
))}
</tr>
))}
</thead>
<tbody>
{getRowModel().rows.map((row) => (
<tr key={row.id}>
{row.getVisibleCells().map((cell) => (
<td key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</td>
))}
</tr>
))}
</tbody>
</Table>
<br />
<Pagination
position="right"
total={pageCount}
page={current}
onChange={setCurrent}
/>
</List>
);
};

interface IPost {
id: number;
title: string;
}

Properties​

recordItemId​

recordItemId allows us to manage which record will be deleted.

http://localhost:3000
import { DeleteButton } from "@pankod/refine-mantine";

const MyDeleteComponent = () => {
return <DeleteButton recordItemId="123" />;
};

Clicking the button will trigger the useDelete method and then the record whose resource is "post" and whose id is "123" gets deleted.

note

<DeleteButton> component reads the id information from the route by default.

resourceNameOrRouteName​

resourceNameOrRouteName allows us to manage which resource's record is going to be deleted.

http://localhost:3000
import { DeleteButton } from "@pankod/refine-mantine";

const MyDeleteComponent = () => {
return (
<DeleteButton resourceNameOrRouteName="categories" recordItemId="2" />
);
};

Clicking the button will trigger the useDelete method and then the record whose resource is "categories" and whose id is "2" gets deleted.

note

<DeleteButton> component reads the resource name from the route by default.

onSuccess​

onSuccess can be used if you want to do anything on the result returned after the delete request.

For example, let's console.log after deletion:

http://localhost:3000
import { DeleteButton } from "@pankod/refine-mantine";

const MyDeleteComponent = () => {
return (
<DeleteButton
resourceNameOrRouteName="posts"
recordItemId="1"
onSuccess={(value) => {
console.log(value);
}}
/>
);
};

mutationMode​

Determines which mode mutation will have while executing <DeleteButton>.

Refer to the mutation mode docs for further information. β†’

http://localhost:3000
import { DeleteButton } from "@pankod/refine-mantine";

const MyDeleteComponent = () => {
return <DeleteButton recordItemId="1" mutationMode="undoable" />;
};

hideText​

It is used to show and not show the text of the button. When true, only the button icon is visible.

http://localhost:3000
import { DeleteButton } from "@pankod/refine-mantine";

const MyDeleteComponent = () => {
return <DeleteButton recordItemId="1" hideText />;
};

ignoreAccessControlProvider​

It is used to skip access control for the button so that it doesn't check for access control. This is relevant only when an accessControlProvider is provided to <Refine/>

import { DeleteButton } from "@pankod/refine-mantine";

export const MyListComponent = () => {
return <DeleteButton ignoreAccessControlProvider />;
};

How to override confirm texts?​

You can change the text that appears when you confirm a transaction with confirmTitle prop, as well as what ok and cancel buttons text look like with confirmOkText and confirmCancelText props.

http://localhost:3000
import { DeleteButton } from "@pankod/refine-mantine";

const MyDeleteComponent = () => {
return (
<DeleteButton
recordItemId="1"
confirmTitle="Custom Title"
confirmOkText="Ok Text"
confirmCancelText="Delete Text"
/>
);
};

API Reference​

Properties​