Adaptable

#Infinite Table Integration

Adaptable renders its grid with Infinite Table: <Adaptable.UI.DataGrid /> (part of <Adaptable.UI />) renders an InfiniteTable inside a DataSource, with props computed from the Adaptable state. For most apps the Adaptable API is all you need. For advanced cases you can reach the engine in two ways:

  • Replace the InfiniteTable and DataSource components Adaptable renders, to add props or intercept callbacks.
  • Get the raw Infinite Table APIs.
Warning

Both are escape hatches. Adaptable owns the props it passes to Infinite Table — overriding them can break views, sorting, grouping or selection. Prefer adaptableApi (gridApi, dataSourceApi, viewApi, …) whenever it covers your case.

#Custom InfiniteTable and DataSource components

Pass your own components through the components prop of <Adaptable.Provider />:

Custom InfiniteTable rendering
<script setup lang="ts">
import { h } from 'vue';
import { Adaptable, type AdaptableProps } from '@adaptabletools/datagrid-vue';
import { InfiniteTable, DataSource } from '@infinite-table/infinite-vue';

import type { Developer } from '../getting-started/basic.data';

declare const yourExtraProps: Record<string, unknown>;
declare const otherProps: AdaptableProps<Developer>;
declare const data: Developer[];

const components: AdaptableProps<Developer>['components'] = {
  InfiniteTable: (props) => {
    return h(InfiniteTable, { ...props, ...yourExtraProps });
  },
  // the grid is the default slot of the DataSource: pass the slots on
  DataSource: (props, { slots }) => {
    return h(DataSource, { ...props }, slots);
  },
};
</script>

<template>
  <Adaptable.Provider v-bind="otherProps" :data="data" :components="components">
    <Adaptable.UI />
  </Adaptable.Provider>
</template>

Each component receives the props Adaptable computed for it — columns, column order and sizing, sort info, group by, selection and their change handlers — and must render the real InfiniteTable / DataSource with them.

Each of them is a function, as above, or a component:

  • A function is called with all the props, and with the context (slots, attrs) as its second argument, and what it returns is rendered. The DataSource has to pass the slots on: the grid is its default slot.
  • A component (a .vue file, defineComponent) is what calls a composable. The props Adaptable computed are its attrs: it declares none of them, sets inheritAttrs: false and passes them on, as any component that wraps another does in Vue.
A custom InfiniteTable as a component
<script setup lang="ts">
import { useAttrs } from 'vue';
import { InfiniteTable } from '@infinite-table/infinite-vue';
import { useAdaptableState } from '@adaptabletools/datagrid-vue';

// the props Adaptable computed are the attrs of this component: it declares
// none of them, and passes them on itself
defineOptions({ inheritAttrs: false });
const attrs = useAttrs();

const viewId = useAdaptableState((state) => state.view.currentViewId);
</script>

<template>
  <InfiniteTable v-bind="attrs" :loadingText="`Loading the ${viewId} view…`" />
</template>

When you intercept a callback Adaptable already provides, call the original too, or Adaptable's state stops following the grid:

InfiniteTable: (props) => {
  const onColumnOrderChange: typeof props.onColumnOrderChange = (columnOrder) => {
    console.log('columnOrder', columnOrder);
    // keep Adaptable in sync
    props.onColumnOrderChange?.(columnOrder);
  };
  return h(InfiniteTable, { ...props, onColumnOrderChange });
},
Note

Create the components object once: in <script setup> or outside the component, not in the template or in a computed. A new InfiniteTable / DataSource function or component unmounts and remounts the grid.

Your custom components are rendered inside the provider, so a component can call the composables in its setup — for example useAdaptableState or useAdaptableApi.

The same components prop also accepts Infinite Table's own component overrides (they are passed through to InfiniteTable), and Adaptable's replaceable parts such as the settings panel view editors — see Replacing built-in parts.

#
Intercepting InfiniteTable and DataSource callbacks

The custom InfiniteTable logs column order changes and the custom DataSource logs data loads, while both still call the handlers Adaptable passed in.

Drag a column header to a new position and watch the log above the grid.

open
loading demo…

#The raw Infinite Table APIs

The @adaptabletools/datagrid-vue/infinite entry point gives you engine access:

ScrollToTop.vue
<script setup lang="ts">
import { useAdaptableApi } from '@adaptabletools/datagrid-vue';
import { getInfiniteTableApi } from '@adaptabletools/datagrid-vue/infinite';

const adaptableApi = useAdaptableApi();
const scrollToTop = () => {
  getInfiniteTableApi(adaptableApi).scrollTop = 0;
};
</script>

<template>
  <button @click="scrollToTop">Scroll to top</button>
</template>
  • getInfiniteTableApi(adaptableApi) — the Infinite Table API.
  • getInfiniteDataSourceApi(adaptableApi) — the Infinite DataSourceApi.
  • InfiniteTable, DataSource and debug re-exported from @infinite-table/infinite-vue, plus the InfiniteTableApi, InfiniteTableProps, DataSourceApi, DataSourceProps and InfiniteTableRowInfo types.

The same APIs are available as adaptableApi.getInfiniteTableApi() and adaptableApi.getInfiniteDataSourceApi(). They throw until the grid is mounted — call them from event handlers or after onReady.