Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

Filter custom block content by Airtable View

Topic Labels: Custom extensions
Solved
Jump to Solution
496 1
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to create a Dropdown Menu inside a custom Block to filter by own configured Airtable Views?

I’am not quite sure if this is what would work for my case.
Is there any Example Demo/Code for that?

Thanks!

1 Solution

Accepted Solutions

Can I assume that you’re programming this custom Block? If so, then I believe what you’re looking for is ViewPicker:

import React, { useState } from "react";
import { ViewPicker, useBase } from "@airtable/blocks/ui";
const ViewPickerExample = () => {
  const [view, setView] = useState(null);
  const base = useBase();
  const table = base.getTableByNameIfExists("Tasks");
  // If table is null or undefined, the ViewPicker will not render.
  return (
    <ViewPicker
      table={table}
      view={view}
      onChange={newView => setView(newView)}
      width="320px"
    />
  );
};

You can sync that up to globalConfig, with ViewPickerSynced:

import React from "react";
import { useBase, ViewPickerSynced } from "@airtable/blocks/ui";
const ViewPickerSyncedExample = () => {
  const base = useBase();
  const table = base.getTableByNameIfExists("Tasks");
  // If table is null or undefined, the ViewPickerSynced will not render.
  return (
    <ViewPickerSynced table={table} globalConfigKey="viewId" width="320px" />
  );
};

See Solution in Thread

1 Reply 1

Can I assume that you’re programming this custom Block? If so, then I believe what you’re looking for is ViewPicker:

import React, { useState } from "react";
import { ViewPicker, useBase } from "@airtable/blocks/ui";
const ViewPickerExample = () => {
  const [view, setView] = useState(null);
  const base = useBase();
  const table = base.getTableByNameIfExists("Tasks");
  // If table is null or undefined, the ViewPicker will not render.
  return (
    <ViewPicker
      table={table}
      view={view}
      onChange={newView => setView(newView)}
      width="320px"
    />
  );
};

You can sync that up to globalConfig, with ViewPickerSynced:

import React from "react";
import { useBase, ViewPickerSynced } from "@airtable/blocks/ui";
const ViewPickerSyncedExample = () => {
  const base = useBase();
  const table = base.getTableByNameIfExists("Tasks");
  // If table is null or undefined, the ViewPickerSynced will not render.
  return (
    <ViewPickerSynced table={table} globalConfigKey="viewId" width="320px" />
  );
};