useDatasheet
A hook for connecting a React component to your datasheet's schema. Datasheet will provide the interface to make update to datasheet date, and check permission.
Parameters
Name | Type |
---|---|
datasheetId? | string |
Returns
undefined
| Datasheet
Datasheet instance
Example
import { useDatasheet } from '@apitable/widget-sdk';
function AddRecord() {
const datasheet = useDatasheet();
const [error, setError] = useState();
// The key of the parameter is the fieldId and the value is the cell value
const valuesMap = {
fld1234567980: 'this is a text value',
fld0987654321: 1024,
}
function addRecord(valuesMap) {
if (!datasheet) {
return;
}
const permission = datasheet.checkPermissionsForAddRecord(valuesMap)
if (permission.acceptable) {
datasheet.addRecord(valuesMap);
return;
}
setError(permission.message);
}
return (<div>
{error && <p>{error}</p>}
<button onClick={() => addRecord(valuesMap)}>add a new record</button>
</div>);
}