Skip to main content

useRecords

Gets all the records under a given view in the datasheet. Rerendering is triggered when the value of record, view configuration, field configuration changes. Get all the records may cause lag due to a sharp increase in computation, so please use caution and test well.

Parameters

NameTypeDescription
viewIdstring | undefinedThe ID for the view, pass undefined to return an empty array.
query?IRecordQueryquery configuration parameters.

Returns

DynamicRecord[]

Example

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

// Show record name
function RecordsTitle() {
const viewId = useActiveViewId();
const records = useRecords(viewId);
return (<div>
{records.map(record => <p>{record.title}</p>)}
</div>);
}

useRecords(datasheet, viewId, query?): DynamicRecord[]

Support for loading the corresponding datasheet data records.

Parameters

NameTypeDescription
datasheetDatasheet | undefinedDatasheet instance, by useDatasheet get.
viewIdstring | undefinedView ID, passing in undefined returns an empty array.
query?IRecordQueryquery configuration parameters.

Returns

DynamicRecord[]

Example

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

// Show the primary key of records the corresponding to the datasheetId(dstXXXXXXXX) datasheet
function RecordsTitle() {
const datasheet = useDatasheet('dstXXXXXXXX');
const viewsMeta = useViewsMeta(datasheet);
const records = useRecords(datasheet, viewsMeta[0]?.id);
return (
<div>
{records.map(record => <p>{record.title}</p>)}
</div>
);
}