Skip to main content

useFields

Get information about all fields(columns) of currently view. Rerendering is triggered when the fields property/columns order changes.

If not viewId passed in, an empty array is returned.

Parameters

NameTypeDescription
viewIdstring | undefinedThe ID for view.
query?IFieldQueryOptional parameter that specifies which fieldId data to query.

Returns

Field[]

Example

import { useFields, useActiveViewId } from '@apitable/widget-sdk';

// Show all field names
function FieldNames() {
const viewId = useActiveViewId();
const fields = useFields(viewId);
return (<div>
{fields.map(field => <p key={field.id}>{field.name}</p>)}
</div>);
}

useFields(datasheet, viewId, query?): Field[]

Support for loading the corresponding datasheet data fields.

Parameters

NameTypeDescription
datasheetDatasheet | undefinedDatasheet instance, by useDatasheet get.
viewIdstring | undefinedThe ID for view.
query?IFieldQueryOptional parameter that specifies which fieldId data to query.

Returns

Field[]

Example

import { useFields, useDatasheet } from '@apitable/widget-sdk';

// Show all field names corresponding to the datasheetId(dstXXXXXXXX) datasheet
function FieldNames() {
const datasheet = useDatasheet('dstXXXXXXXX');
const fields = useFields(datasheet, 'vieXXXXXXX');
return (<div>
{fields.map(field => <p key={field.id}>{field.name}</p>)}
</div>);
}