Skip to content

Commit c66f8f9

Browse files
Copilothotlong
andcommitted
Add quick start guide for ObjectAgGrid
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a7bf8b3 commit c66f8f9

1 file changed

Lines changed: 186 additions & 0 deletions

File tree

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# Quick Start Guide - ObjectAgGrid
2+
3+
## Installation
4+
5+
The ObjectAgGrid component is already installed as part of the @object-ui/plugin-aggrid package.
6+
7+
## Basic Usage
8+
9+
### Step 1: Import Required Packages
10+
11+
```typescript
12+
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
13+
import '@object-ui/plugin-aggrid'; // Auto-registers the component
14+
```
15+
16+
### Step 2: Create a Data Source
17+
18+
```typescript
19+
const dataSource = new ObjectStackAdapter({
20+
baseUrl: 'https://your-api.example.com',
21+
token: 'your-auth-token' // Optional
22+
});
23+
```
24+
25+
### Step 3: Define Your Schema
26+
27+
```typescript
28+
const gridSchema = {
29+
type: 'object-aggrid',
30+
objectName: 'contacts', // The object to fetch from your backend
31+
dataSource: dataSource,
32+
pagination: true,
33+
pageSize: 20,
34+
theme: 'quartz',
35+
height: 600
36+
};
37+
```
38+
39+
### Step 4: Use in Your Component
40+
41+
```typescript
42+
import { SchemaRenderer } from '@object-ui/components';
43+
44+
function MyComponent() {
45+
return (
46+
<div>
47+
<h1>My Contacts</h1>
48+
<SchemaRenderer schema={gridSchema} />
49+
</div>
50+
);
51+
}
52+
```
53+
54+
## Common Use Cases
55+
56+
### Show Only Specific Fields
57+
58+
```typescript
59+
const schema = {
60+
type: 'object-aggrid',
61+
objectName: 'contacts',
62+
dataSource: dataSource,
63+
fieldNames: ['name', 'email', 'phone', 'company'], // Only show these
64+
pagination: true
65+
};
66+
```
67+
68+
### Enable Inline Editing
69+
70+
```typescript
71+
const schema = {
72+
type: 'object-aggrid',
73+
objectName: 'tasks',
74+
dataSource: dataSource,
75+
editable: true,
76+
singleClickEdit: true, // Single-click to edit
77+
callbacks: {
78+
onCellValueChanged: (event) => {
79+
console.log('Updated:', event.data);
80+
// Changes are automatically saved to backend!
81+
}
82+
}
83+
};
84+
```
85+
86+
### Add Filters and Sorting
87+
88+
```typescript
89+
const schema = {
90+
type: 'object-aggrid',
91+
objectName: 'products',
92+
dataSource: dataSource,
93+
filters: {
94+
category: 'Electronics',
95+
price: { $lt: 1000 }
96+
},
97+
sort: {
98+
price: 'asc'
99+
}
100+
};
101+
```
102+
103+
### Enable CSV Export
104+
105+
```typescript
106+
const schema = {
107+
type: 'object-aggrid',
108+
objectName: 'sales',
109+
dataSource: dataSource,
110+
exportConfig: {
111+
enabled: true,
112+
fileName: 'sales-report.csv'
113+
}
114+
};
115+
```
116+
117+
## What Happens Automatically
118+
119+
When you use ObjectAgGrid, it automatically:
120+
121+
1. ✅ Fetches the object schema (field definitions) from your backend
122+
2. ✅ Generates appropriate column definitions based on field types
123+
3. ✅ Applies proper formatters (currency, dates, percentages, etc.)
124+
4. ✅ Loads data with pagination
125+
5. ✅ Saves edits back to the backend (when `editable: true`)
126+
127+
## Field Types Automatically Formatted
128+
129+
- **Currency**: `$1,234.56`
130+
- **Percent**: `45.5%`
131+
- **Date**: Localized date format
132+
- **Boolean**: ✓ Yes / ✗ No
133+
- **Email**: Clickable mailto links
134+
- **Phone**: Clickable tel links
135+
- **URL**: Clickable external links
136+
- **Color**: Color swatches
137+
- **Rating**: Star ratings ⭐⭐⭐⭐⭐
138+
- And 20+ more field types!
139+
140+
## Backend Requirements
141+
142+
Your ObjectStack backend should provide:
143+
144+
1. **Metadata Endpoint**: Returns object schema with field definitions
145+
```typescript
146+
GET /api/meta/objects/{objectName}
147+
```
148+
149+
2. **Data Endpoint**: Returns paginated data
150+
```typescript
151+
GET /api/data/{objectName}?$top=20&$skip=0
152+
```
153+
154+
3. **Update Endpoint** (for editable grids):
155+
```typescript
156+
PATCH /api/data/{objectName}/{id}
157+
```
158+
159+
## Next Steps
160+
161+
- See `OBJECT_AGGRID_CN.md` for Chinese documentation
162+
- See `examples/object-aggrid-demo.tsx` for complete examples
163+
- See `README.md` for full API reference
164+
165+
## Troubleshooting
166+
167+
**Data not loading?**
168+
- Check that your `dataSource` is properly initialized
169+
- Verify the `objectName` exists in your backend
170+
- Check browser console for errors
171+
172+
**Columns not showing?**
173+
- Verify your object schema has field definitions
174+
- Check that fields have `name` and `type` properties
175+
176+
**Editing not working?**
177+
- Make sure `editable: true` is set
178+
- Verify fields are not marked as `readonly`
179+
- Check that your backend update endpoint is working
180+
181+
## Support
182+
183+
For issues or questions, please refer to:
184+
- Full documentation in `README.md`
185+
- Chinese documentation in `OBJECT_AGGRID_CN.md`
186+
- Implementation details in `IMPLEMENTATION_SUMMARY.md`

0 commit comments

Comments
 (0)