Search results

How To

Work in offline mode

On remote data binding, every time invoking executeQuery will send request to the server and the query will be processed on server-side. To avoid post back to server on calling executeQuery, you can set the DataManager to load all the data on initialization time and make the query processing in client-side. To enable this behavior, you can use offline property of DataManager.

Source
Preview
app.vue
<template>
  <div id="app">
    <table class='e-table'>
        <tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
        <tr v-for="item in items">
            <td>{{item.OrderID}}</td><td>{{item.CustomerID}}</td><td>{{item.EmployeeID}}</td>
        </tr>
    </table>
  </div>
</template>

<script>
import Vue from 'vue';
import { DataManager, Query, ODataAdaptor } from '@syncfusion/ej2-data';

let SERVICE_URI = 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders/?$top=7';

export default {
  data () {
    return {
        items: []
    }
  },
  created () {
      new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor, offline: true }).ready.then((e) => {
        this.items = e.result;
    });
  }
}
</script>
<style>
    .e-table {
      border: solid 1px #e0e0e0;
      border-collapse: collapse;
      font-family: Roboto;
  }

  .e-table td, .e-table th {
      border-style: solid;
      border-width: 1px 0 0;
      border-color: #e0e0e0;
      display: table-cell;
      font-size: 14px;
      line-height: 20px;
      overflow: hidden;
      padding: 8px 21px;
      vertical-align: middle;
      white-space: nowrap;
      width: auto;
  }
</style>


{% endraw %}

The loaded data will be cached in the json property of DataManager.

Sending additional parameters to server

You can use the addParams method of Query class, to add custom parameter to the data request.

Source
Preview
app.vue
<template>
  <div id="app">
    <table class='e-table'>
        <tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
        <tr v-for="item in items">
            <td>{{item.OrderID}}</td><td>{{item.CustomerID}}</td><td>{{item.EmployeeID}}</td>
        </tr>
    </table>
  </div>
</template>

<script>
import Vue from 'vue';
import { DataManager, Query, ODataAdaptor } from '@syncfusion/ej2-data';

let SERVICE_URI = 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders/';

export default {
  data () {
    return {
        items: []
    }
  },
  created () {
      new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor })
    .executeQuery(new Query().addParams('$top', '7')).then((e) => {
        this.items = e.result;
    });
  }
}
</script>
<style>
    .e-table {
      border: solid 1px #e0e0e0;
      border-collapse: collapse;
      font-family: Roboto;
  }

  .e-table td, .e-table th {
      border-style: solid;
      border-width: 1px 0 0;
      border-color: #e0e0e0;
      display: table-cell;
      font-size: 14px;
      line-height: 20px;
      overflow: hidden;
      padding: 8px 21px;
      vertical-align: middle;
      white-space: nowrap;
      width: auto;
  }
</style>


{% endraw %}

Adding custom headers

You can add custom headers to the request made by DataManager using the headers property.

import { DataManager, Query, ODataAdaptor } from '@syncfusion/ej2-data';

let SERVICE_URI =  'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders/';

new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor, headers:[{ 'syncfusion': 'true' }] })
    .executeQuery(new Query())
    .then((e) => {
        //get result from e.result
    });

Adding custom headers while making cross domain request will initiate preflight request.