Renders a complex Data Grid component with id wrapper. See modules for information on how to use them.

Parameters:
NameTypeDescription
propsobject

Component props.

Properties
NameTypeDescription
afterGridHeadingJSX.Element

Element to render after the grid heading.

columnsobject

Array of column objects. Supply: component, key, props, sortable (optional), hideAt (optional). Key is used to match data keys for cells.

columnRowAttributesobject

Custom attributes for the column row.

columnRowClassesstring | Array | object

Custom classes for the column row.

columnStylePropsobject

Style props for the column.

customAttributesobject

Custom attributes for the component

customClassesstring | Array | object

Custom classes for the component.

dataobject

The data for the component.

dataPerPagenumber

The number of data rows to show per page.

dataRowAttributesobject

Custom attributes for the data row.

dataRowClassesstring | Array | object

Custom classes for the data row.

dataRowMinHeightstring

The minimum height for the data row.

EmptyImageJSX.Element

The image to show when there is no data.

emptyMessageAttributesboolean

Custom attributes for the empty message.

emptyMessageClassesstring | Array | object

Custom classes for the empty message.

equalGridboolean

Whether the grid should be equal.

gridControlWrapperClassesstring | Array | object

Custom classes for the grid control wrapper.

gridLockedboolean

Whether the grid should be locked.

handleGridClicksfunction

Passed handler for grid clicks if the field type supports it.

highlightHoverboolean

Whether the grid should highlight a row on hover.

highlightSelectedboolean

Whether the grid should highlight a selected row.

i18nobject

Language strings for the component.

Properties
NameTypeDescription
emptyMessageI18nstring

The empty message for the data grid.

emptyTitleI18nstring

The empty title for the data grid.

gridHeadingI18nstring

The heading for the data grid.

idstring

The ID for the component.

isLoadingboolean

Whether the data grid is loading.

maintainHeightboolean

Whether the grid should maintain height at all times.

modulesArray

The modules for the data grid.

moduleAttributesobject

Custom attributes for the modules.

moduleStateobject

The state for the modules.

scrollXboolean

Whether the grid should have horizontal scrolling.

setGridDatafunction

Passed handler for field changes if the field type supports it.

setIsLoadingfunction

Handler to update the loading state.

showColumnsboolean

Whether to show the column row(s).

showColumnsInFooterboolean

Whether the column row should be in the footer as well.

spacingstring | number | Array | object

The spacing for the component, as a string, number, array, or object.

titleAttributesobject

Custom attributes for the title.

titleClassesstring | Array | object

Custom classes for the title.

updateModuleStatefunction

Handler to update the module state.

useAjaxboolean

Whether to use ajax for the data grid.

refobject | null

Ref to the component.

Since
  • 3.3.0
Returns:

The DataGrid component.

Type: 
JSX.Element
Example
import DataGrid from '@gravityforms/components/react/admin/modules/DataGrid';
import {
  ActiveFilters,
  BulkActions,
  ColumnSort,
  DateFilters,
  GridPagination,
  Search,
  SimpleFilters,
} from '@gravityforms/components/react/admin/modules/DataGrid/modules';
import useDataGridState from '@gravityforms/components/react/admin/modules/DataGrid/use-data-grid-state';
import StatusIndicator from '@gravityforms/components/react/admin/elements/StatusIndicator';
import Text from '@gravityforms/components/react/admin/elements/Text';

const activeFiltersAttributes = {
  pill: {
    icon: 'x-circle',
    iconPrefix: 'gravity-component-icon',
    onClick: ( event ) => {},
    // ...restPillAttributes (see Pill component)
  },
  reset: {
    label: 'Reset Filters',
    onClick: ( event ) => {},
    // ...restButtonAttributes (see Button component)
  },
  i18n: {
    activeFiltersLabel: 'Filters:',
  },
  onFilterChange: ( state ) => {},
};

const bulkActionsAttributes = {
  button: {
    label: 'Apply',
    onClick: ( state ) => {},
    // ...restButtonAttributes (see Button component)
  },
  select: {
    blankValue: -1,
    onChange: ( value ) => {},
    wrapperClasses: [],
    labelAttributes: {
      label: 'Select an action',
      isVisible: false,
    },
    options: [
      {
        label: 'Bulk Actions',
        value: '-1',
      },
      {
        label: 'Delete',
        value: 'delete',
      },
    },
    // ...restSelectAttributes (see Select component)
  },
  i18n: {
    bulkSelectI18n: 'Select all rows',
    selectNoticeSelectedNumberEntriesI18n: 'All %1$s rows on this page are selected',
    selectNoticeSelectedAllNumberEntriesI18n: 'All %1$s rows in this table are selected',
    selectNoticeSelectAllNumberEntriesI18n: 'Select All %1$s Rows',
    selectNoticeClearSelectionI18n: 'Clear Selection',
    selectRowI18n: 'Select row',
  },
  notice: {
    rowCount: 315, // Total number of rows in the data grid.
  },
};

const columnSortAttributes = {
  sortButton: {
    customClasses: [],
    iconAsc: 'chevron-up',
    iconDesc: 'chevron-down',
    iconPrefix: 'gravity-component-icon',
    initialOrder: 'DESC',
    onClick: ( state ) => {},
  },
};

const dateFiltersAttributes = {
  calendarAttributes: {
    // ...restCalendarAttributes (see Calendar component)
  },
  customClasses: [],
  dateFormatOptions: {
    day: 'numeric',
    month: 'short',
    year: 'numeric',
  },
  triggerAttributes: {
    ariaText: 'Calendar',
    icon: 'calendar',
    iconPrefix: 'gravity-component-icon',
    // ...restButtonAttributes (see Button component)
  },
  onChange: ( state ) => {},
  resetAttributes: {
    label: 'Reset',
    // ...restResetAttributes (see Button component)
  },
  todayAttributes: {
    label: 'Today',
    // ...restTodayAttributes (see Button component)
  },
  i18n: {
    pillLabel: 'Date: %s',
  },
  // ...restDateFiltersAttributes (see Calendar component)
};

const paginationAttributes = {
  nextLabel: 'Next',
  nextAriaLabel: 'Next page',
  onClick: ( state ) => {},
  onPageChange: ( event ) => {},
  pageCount: 15,
  previousLabel: 'Prev',
  previousAriaLabel: 'Previous page',
  // ...restPaginationAttributes (see Pagination component)
};

const searchAttributes = {
  input: {
    onChange: ( value ) => {},
    onClear: () => {},
    onKeyDown: ( event ) => {},
    wrapperClasses: [],
    // ...restInputAttributes (see Input component)
  },
  button: {
    customClasses: [],
    // ...restButtonAttributes (see Button component)
  },
  onSearch: ( state ) => {},
  i18n: {
    noResultsTitle: 'No results found',
    noResultsMessage: 'Try adjusting your search criteria.',
    pillLabel: 'Search: %s',
  },
  noResults: {
    customClasses: [],
    Image: NoResultsImage,
    // ...restAttributes (for NoResults component)
  },
};

const simpleFiltersAttributes = {
  droplist: {
    customClasses: [],
    listItems: [
      {
        key: 'status',
        triggerAttributes: {
          id: 'status',
          label: 'Status',
        },
        listItems: [
          {
            key: 'status-sent',
            props: {
              customAttributes: {
                'data-key': 'status',
                'data-value': 'sent',
                'data-pill-label': 'Status: Sent',
                id: 'status-sent',
              },
              element: 'button',
              label: 'Sent',
            },
          },
          {
            key: 'status-failed',
            props: {
              customAttributes: {
                'data-key': 'status',
                'data-value': 'failed',
                'data-pill-label': 'Status: Failed',
                id: 'status-failed',
              },
              element: 'button',
              label: 'Failed',
            },
          },
        ],
      },
      {
        key: 'service',
        triggerAttributes: {
          id: 'service',
          label: 'Service',
        },
        listItems: [
          {
            key: 'service-mailgun',
            props: {
              customAttributes: {
                'data-key': 'service',
                'data-value': 'mailgun',
                'data-pill-label': 'Service: Mailgun',
                id: 'service-mailgun',
              },
              element: 'button',
              label: 'Mailgun',
            },
          },
          {
            key: 'service-sendgrid',
            props: {
              customAttributes: {
                'data-key': 'service',
                'data-value': 'sendgrid',
                'data-pill-label': 'Service: SendGrid',
                id: 'service-sendgrid',
              },
              element: 'button',
              label: 'SendGrid',
            },
          },
        ],
      },
    ],
    listItemAttributes: {
      iconAfter: 'check-alt',
      groupIcon: 'chevron-right',
      iconPrefix: 'gravity-component-icon',
    },
    reset: {
      hasReset: true,
      label: 'Reset Filters',
    },
    triggerAttributes: {
      ariaId: 'aria-text',
      ariaText: 'Filter by',
      icon: 'filter',
      iconPrefix: 'gravity-component-icon',
      size: 'size-height-m',
      // ...restTriggerAttributes (see Droplist component)
    },
    // ...restDroplistAttributes (see Droplist component)
  },
};

const modules = [ ActiveFilters, BulkActions, ColumnSort, DateFilters, GridPagination, Search, SimpleFilters ];

const moduleAttributes = {
  activeFilters: activeFiltersAttributes,
  bulkActions: bulkActionsAttributes,
  columnSort: columnSortAttributes,
  dateFilters: dateFiltersAttributes,
  pagination: paginationAttributes,
  search: searchAttributes,
  simpleFilters: simpleFiltersAttributes,
};

const columns = [
  {
    component: Text,
    hideWhenLoading: true,
    key: 'status',
    props: {
      content: 'Status',
      size: 'text-sm',
      weight: 'medium',
    },
    sortable: true,
    variableLoader: true,
  },
  {
    component: Text,
    hideAt: 960,
    hideWhenLoading: true,
    key: 'service',
    props: {
      content: 'Service',
      size: 'text-sm',
      weight: 'medium',
    },
    sortable: true,
  },
];

const columnStyleProps = {
  status: { flex: '0 0 120px' },
  service: { flexBasis: '100px' },
};

const initialData = [
  {
    status: {
      component: StatusIndicator,
      props: {
        label: 'Sent',
      },
    },
    service: {
      component: Text,
      props: {
        content: 'Mailgun',
        size: 'text-sm',
      },
    },
  },
  {
    status: {
      component: StatusIndicator,
      props: {
        label: 'Failed',
      },
    },
    service: {
      component: Text,
      props: {
        content: 'SendGrid',
        size: 'text-sm',
      },
    },
  }
];

const useAjax = true;

const {
  moduleState,
  updateModuleState,
  isLoading,
  setIsLoading,
  gridLocked,
  organizedData,
} = useDataGridState( {
  data: initialData,
  dataPerPage: 10,
  initialState: {
    isLoading: false,
    moduleState: {
      currentPage: 0,
      searchTerm: '',
      searchActive: false,
    },
  },
  modules,
  moduleAttributes,
  useAjax,
} );

return <DataGrid
  columns={ columns }
  columnStyleProps={ columnStyleProps }
  data={ organizedData }
  dataPerPage={ 10 }
  EmptyImage={ EmptyImageSvg }
  emptyMessageAttributes={ { style: { maxWidth: '360px' } } },
  gridLocked={ gridLocked }
  i18n={ {
    emptyMessageI18n: 'No data available',
    emptyTitleI18n: 'No Data',
    gridHeadingI18n: 'Data Grid Title',
  } }
  isLoading={ isLoading }
  modules={ modules }
  moduleAttributes={ moduleAttributes }
  moduleState={ moduleState }
  setIsLoading={ setIsLoading }
  updateModuleState={ updateModuleState }
  useAjax={ useAjax }
/>;