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 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
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { DataManager, Query, ReturnOption, ODataAdaptor } from '@syncfusion/ej2-data';
import { data } from './datasource';
interface Orders { OrderID: number; EmployeeID: number; CustomerID: string; Order_Details: Object[]; }
function Row(props: { item: Orders }) {
    let item: Object = props.item;
    return (<tr>
             <td>{item.OrderID}</td>
             <td>{item.CustomerID}</td>
             <td>{item.EmployeeID}</td>
            </tr>)
}

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

class DataTable extends React.Component<{}, {}> {
     constructor(props: Object) {
        super(props);
        this.state = { items: [] };
        let dm: DataManager = new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor, offline: true }, new Query().take(8));
        dm.ready.then((e: ReturnOption) => {
            this.setState({
                items: e.result.map((data: Object) => <Row item={data}></Row>)
            });
        });
     }

    render() {
        return (<table id='datatable' class='e-table'>
                <thead>
                    <tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
                </thead>
                <tbody>{this.state.items}</tbody>
            </table>)
    }
}

ReactDOM.render(<DataTable />, document.getElementById('container'));

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
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { DataManager, Query, ReturnOption, ODataAdaptor } from '@syncfusion/ej2-data';
import { data } from './datasource';
interface Orders { OrderID: number; EmployeeID: number; CustomerID: string; Order_Details: Object[]; }
function Row(props: { item: Orders }) {
    let item: Object = props.item;
    return (<tr>
             <td>{item.OrderID}</td>
             <td>{item.CustomerID}</td>
             <td>{item.EmployeeID}</td>
            </tr>)
}

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

class DataTable extends React.Component<{}, {}> {
     constructor(props: Object) {
        super(props);
        this.state = { items: [] };
        new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor })
        .executeQuery(new Query().addParams('$top', '8'))
        .then((e: ReturnOption) => {
            this.setState({
                items: e.result.map((data: Object) => <Row item={data}></Row>)
            });
        });
     }

    render() {
        return (<table id='datatable' class='e-table'>
                <thead>
                    <tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
                </thead>
                <tbody>{this.state.items}</tbody>
            </table>)
    }
}

ReactDOM.render(<DataTable />, document.getElementById('container'));

Adding custom headers

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

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

const SERVICE_URI: string =  '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: ReturnOption) => {
        //get result from e.result
    });

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