Lattice Grid Buy a licence

demo D229

Pushdown to a live OData service in Vue

A grid over the public Northwind service; filter and sort are pushed to it, and lastPlan shows the split

createPushdownSource · odataAdapter · lastPlan()

This grid runs over the public Northwind OData service, pushing filter and sort to the service and showing the query plan it produced. It shows the grid working directly against a live standards-based API, with the split between what the server did and what the grid did on screen.

Building…
Loading a live grid…

This is the Vue 3 version. A createLatticeGrid component takes the configuration through v-bind, and reactive data flows straight into the grid, so it updates the way the rest of your Vue app does.

The configuration

<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
<style>
  #grid > div { height: 520px; }
</style>
<div id="grid"></div>

<script type="module">
  import * as Vue from 'https://esm.sh/vue@3/dist/vue.esm-browser.prod.js';
  import * as lattice from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
  import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/vue.esm.min.js';

  const { createGrid, odataAdapter, createPushdownSource } = lattice;
  const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });

  // The adapter takes a URL and imports nothing. createPushdownSource turns the
  // grid's query into an OData request and finishes any residual in the grid.
  const adapter = odataAdapter({
    url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Orders',
  });
  const source = createPushdownSource({
    adapter,
    compute: lattice,   // the grid's own kernels, for anything the service could not do
    pageSize: 100,
  });

  Vue.createApp({
    components: { LatticeGrid },
    data() {
      return {
        config: {
          rowKey: 'OrderID',
          toolPanel: { side: 'left', panels: ['filters', 'columns'] },
          columns: [
            { field: 'OrderID', title: 'Order', type: 'number' },
            { field: 'CustomerID', title: 'Customer', filter: { type: 'set' } },
            { field: 'ShipCountry', title: 'Ship to', filter: { type: 'set' } },
            { field: 'Freight', title: 'Freight', type: 'number' },
            { field: 'OrderDate', title: 'Ordered', type: 'dateString' },
          ],
          source,
        },
      };
    },
    mounted() {
      const grid = this.$refs.grid.grid();
      // After each query, lastPlan() reports what the service ran and what stayed here.
      grid.on('rows:changed', () => {
        const plan = source.lastPlan();
        if (plan) console.log(plan.unpushed.length ? 'pushed part' : 'pushed all', plan);
      });
    },
    template: '<lattice-grid ref="grid" v-bind="config" />',
  }).mount('#grid');
</script>