Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/data/toolpad/core/components/data-grid/BasicDataProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

const myData = createDataProvider({
// preview-start
async getMany() {
return {
rows: [
{ id: '1', name: 'John' },
{ id: '2', name: 'Jane' },
],
};
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function BasicDataProvider() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
29 changes: 29 additions & 0 deletions docs/data/toolpad/core/components/data-grid/BasicDataProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

const myData = createDataProvider({
// preview-start
async getMany() {
return {
rows: [
{ id: '1', name: 'John' },
{ id: '2', name: 'Jane' },
],
};
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function BasicDataProvider() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
async getMany() {
return {
rows: [
{ id: '1', name: 'John' },
{ id: '2', name: 'Jane' },
],
};
},
43 changes: 43 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

let nextId = 1;
const getNextId = () => {
const id = `id-${nextId}`;
nextId += 1;
return id;
};
let DATA = [
{ id: getNextId(), name: 'John' },
{ id: getNextId(), name: 'Jane' },
];

const myData = createDataProvider({
async getMany() {
return {
rows: DATA,
};
},
// preview-start
async createOne(values) {
const id = getNextId();
const newItem = { ...values, id };
DATA = [...DATA, newItem];
return newItem;
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function CrudCreate() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
43 changes: 43 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

let nextId = 1;
const getNextId = () => {
const id = `id-${nextId}`;
nextId += 1;
return id;
};
let DATA = [
{ id: getNextId(), name: 'John' },
{ id: getNextId(), name: 'Jane' },
];

const myData = createDataProvider({
async getMany() {
return {
rows: DATA,
};
},
// preview-start
async createOne(values) {
const id = getNextId();
const newItem = { ...values, id };
DATA = [...DATA, newItem];
return newItem;
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function CrudCreate() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
async createOne(values) {
const id = getNextId();
const newItem = { ...values, id };
DATA = [...DATA, newItem];
return newItem;
},
40 changes: 40 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudDelete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

let nextId = 1;
const getNextId = () => {
const id = `id-${nextId}`;
nextId += 1;
return id;
};
let DATA = [
{ id: getNextId(), name: 'John' },
{ id: getNextId(), name: 'Jane' },
];

const myData = createDataProvider({
async getMany() {
return {
rows: DATA,
};
},
// preview-start
async deleteOne(id) {
DATA = DATA.filter((item) => item.id !== id);
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function CrudDelete() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
40 changes: 40 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudDelete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

let nextId = 1;
const getNextId = () => {
const id = `id-${nextId}`;
nextId += 1;
return id;
};
let DATA = [
{ id: getNextId(), name: 'John' },
{ id: getNextId(), name: 'Jane' },
];

const myData = createDataProvider({
async getMany() {
return {
rows: DATA,
};
},
// preview-start
async deleteOne(id) {
DATA = DATA.filter((item) => item.id !== id);
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function CrudDelete() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
async deleteOne(id) {
DATA = DATA.filter((item) => item.id !== id);
},
47 changes: 47 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

let nextId = 1;
const getNextId = () => {
const id = `id-${nextId}`;
nextId += 1;
return id;
};
let DATA = [
{ id: getNextId(), name: 'John' },
{ id: getNextId(), name: 'Jane' },
];

const myData = createDataProvider({
async getMany() {
return {
rows: DATA,
};
},
// preview-start
async updateOne(id, values) {
console.log(id, values);
const existing = DATA.find((item) => item.id === id);
if (!existing) {
throw new Error(`Item with id ${id} not found`);
}
const updated = { ...existing, ...values };
DATA = DATA.map((item) => (item.id === updated.id ? updated : item));
return updated;
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function CrudUpdate() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
47 changes: 47 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudUpdate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

let nextId = 1;
const getNextId = () => {
const id = `id-${nextId}`;
nextId += 1;
return id;
};
let DATA = [
{ id: getNextId(), name: 'John' },
{ id: getNextId(), name: 'Jane' },
];

const myData = createDataProvider({
async getMany() {
return {
rows: DATA,
};
},
// preview-start
async updateOne(id, values) {
console.log(id, values);
const existing = DATA.find((item) => item.id === id);
if (!existing) {
throw new Error(`Item with id ${id} not found`);
}
const updated = { ...existing, ...values };
DATA = DATA.map((item) => (item.id === updated.id ? updated : item));
return updated;
},
// preview-end
fields: {
id: { label: 'ID' },
name: { label: 'Name' },
},
});

export default function CrudUpdate() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={250} dataProvider={myData} />
</Box>
);
}
10 changes: 10 additions & 0 deletions docs/data/toolpad/core/components/data-grid/CrudUpdate.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
async updateOne(id, values) {
console.log(id, values);
const existing = DATA.find((item) => item.id === id);
if (!existing) {
throw new Error(`Item with id ${id} not found`);
}
const updated = { ...existing, ...values };
DATA = DATA.map((item) => (item.id === updated.id ? updated : item));
return updated;
},
26 changes: 26 additions & 0 deletions docs/data/toolpad/core/components/data-grid/FieldInference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { createDataProvider } from '@toolpad/core/DataProvider';
import { DataGrid } from '@toolpad/core/DataGrid';
import Box from '@mui/material/Box';

// preview-start
const myData = createDataProvider({
async getMany() {
return {
rows: [
{ id: '1', name: 'John' },
{ id: '2', name: 'Jane' },
],
};
},
// paste fields here:
});
// preview-end

export default function FieldInference() {
return (
<Box sx={{ width: '100%' }}>
<DataGrid height={300} dataProvider={myData} />
</Box>
);
}
Loading